

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1# Elasticsearch Machine Learning C++23## Toolchain4- **Language**: C++20 (`CMAKE_CXX_STANDARD 20`).5- **Build system**: CMake (primary) or Gradle wrapper (`./gradlew`).6- **Compilers**: GCC 13.3.0 on Linux (built from source, installed to `/usr/local/gcc133/`), Xcode Clang on macOS (Xcode 15.2+ for Ventura/Sonoma), Visual Studio 2022 Professional (MSVC) on Windows.7- **Key dependencies**: Boost 1.86.0 (dynamic linking, includes Boost.Json for JSON handling), PyTorch 2.7.1 (libtorch), libxml2.8- **Header-only libraries**: Eigen and valijson are header-only and managed by the `3rd_party/` CMake system (pulled automatically during configuration).9- **Platforms**: Linux x86_64/aarch64, macOS aarch64, Windows x86_64.10- **Toolchain files**: Auto-selected from `cmake/<os>-<arch>.cmake` or set via `CMAKE_TOOLCHAIN_FILE`.1112## Build & Run Commands1314Configure and build (default `RelWithDebInfo`):15```16cmake -B cmake-build-relwithdebinfo17cmake --build cmake-build-relwithdebinfo -j$(nproc)18```1920Or via Gradle:21```22./gradlew :compile23```2425Set `ML_DEBUG=1` to switch to a Debug build. Compiler caching (sccache/ccache) is auto-detected.2627Refer to `CONTRIBUTING.md` and the `build-setup/` directory for full platform-specific setup instructions.2829## Project Structure3031```32bin/ # Application executables33 autodetect/ # Anomaly detection34 categorize/ # Log categorization35 controller/ # Process lifecycle controller36 data_frame_analyzer/ # Data frame analytics (classification, regression)37 normalize/ # Anomaly score normalization38 pytorch_inference/ # PyTorch model inference39lib/ # Shared libraries40 api/ # JSON/REST API layer41 core/ # Platform abstractions, I/O, logging, compression42 maths/ # Mathematical and statistical algorithms43 analytics/ # Boosted tree, data frame analytics44 common/ # Bayesian optimisation, distributions, time series45 time_series/ # Time series decomposition, forecasting46 model/ # Anomaly detection models47 seccomp/ # Seccomp/sandbox filters48 test/ # Shared test utilities (CBoostTestXmlOutput, etc.)49 ver/ # Version information50include/ # Public headers (mirrors lib/ structure)513rd_party/ # Header-only third-party libraries (Eigen, valijson), licenses52cmake/ # CMake toolchain files, helper functions, test runners53build-setup/ # Platform-specific build environment instructions54.buildkite/ # CI pipeline definitions (Buildkite)55.ci/ # Packer scripts for building Orka macOS CI VMs56.github/workflows/ # GitHub Actions (automatic backport)57dev-tools/ # Developer scripts (clang-format, benchmarks)58```5960Libraries must not have circular dependencies. The dependency order is roughly:61`core` -> `maths` -> `model` -> `api` -> `bin/*`.6263## CMake Helper Functions6465The build uses custom CMake functions defined in `cmake/functions.cmake`. Use these instead of raw `add_library`/`add_executable` — they handle platform-specific sources, linking, installation, and Windows resource generation automatically.6667### Adding a Shared Library6869Set `ML_LINK_LIBRARIES` then call `ml_add_library`:7071```cmake72project("ML MyLib")7374set(ML_LINK_LIBRARIES75 ${Boost_LIBRARIES}76 MlCore77 )7879ml_add_library(MlMyLib SHARED80 CMyClass.cc81 CMyOtherClass.cc82 )83```8485Libraries are named with the `Ml` prefix (e.g. `MlCore`, `MlModel`). The function handles shared library versioning, RPATH, and installation. Use `SHARED` for distributed libraries or `STATIC` for internal-only ones.8687For libraries that should not be installed/distributed (e.g. internal helpers), use `ml_add_non_distributed_library` instead.8889### Adding an Executable9091Set `ML_LINK_LIBRARIES` then call `ml_add_executable`. A `Main.cc` file is included automatically — do not list it in the sources:9293```cmake94project("ML MyApp")9596set(ML_LINK_LIBRARIES97 ${Boost_LIBRARIES}98 MlCore99 MlApi100 MlVer101 )102103ml_add_executable(myapp104 CCmdLineParser.cc105 )106```107108The function creates a companion OBJECT library (`MlMyApp`) from the listed sources, which test executables can link against. The executable itself always builds from `Main.cc` plus those objects.109110For executables not intended for distribution (dev tools, benchmarks), use `ml_add_non_distributed_executable`.111112### Adding a Test Executable113114Test executables live in `unittest/` subdirectories. Set `ML_LINK_LIBRARIES` (including `${Boost_LIBRARIES_WITH_UNIT_TEST}` and `MlTest`), then call `ml_add_test_executable`:115116```cmake117project("ML MyLib unit tests")118119set(SRCS120 CMyClassTest.cc121 CMyOtherClassTest.cc122 Main.cc123 )124125set(ML_LINK_LIBRARIES126 ${Boost_LIBRARIES_WITH_UNIT_TEST}127 MlCore128 MlMyLib129 MlTest130 )131132ml_add_test_executable(mylib ${SRCS})133```134135The `_target` argument (e.g. `mylib`) is used to derive the test executable name (`ml_test_mylib`) and the CMake targets `test_mylib` and `test_mylib_individually`.136137### Registering Tests with the Build138139After creating the test executable, register it in `test/CMakeLists.txt` by adding an `ml_add_test` call alongside the existing entries:140141```cmake142ml_add_test(lib/core/unittest core)143ml_add_test(lib/maths/common/unittest maths_common)144ml_add_test(lib/maths/time_series/unittest maths_time_series)145ml_add_test(lib/maths/analytics/unittest maths_analytics)146ml_add_test(lib/model/unittest model)147ml_add_test(lib/api/unittest api)148ml_add_test(lib/ver/unittest ver)149ml_add_test(lib/seccomp/unittest seccomp)150ml_add_test(bin/controller/unittest controller)151ml_add_test(bin/pytorch_inference/unittest pytorch_inference)152ml_add_test(lib/mylib/unittest mylib) # <-- new entry153```154155The first argument is the relative path to the unittest directory; the second is the target name matching `ml_add_test_executable`. Note how nested libraries use underscores in the target name (e.g. `lib/maths/common/unittest` -> `maths_common`).156157### Platform-Specific Sources158159If a source file has a platform-specific variant (e.g. `CMyClass_Linux.cc`, `CMyClass_Darwin.cc`), the `ml_generate_platform_sources` function (called internally by all `ml_add_*` functions) will automatically substitute the platform-specific file at build time. Just list the base filename (`CMyClass.cc`) in your sources.160161## Testing162163Tests use the **Boost.Test** framework. Each library and application has a `unittest/` subdirectory containing test files and a `Main.cc` entry point.164165### Running Tests166167Run all tests:168```169cmake --build cmake-build-relwithdebinfo -t test170```171172Run tests for a specific library:173```174cmake --build cmake-build-relwithdebinfo -t test_core175cmake --build cmake-build-relwithdebinfo -t test_model176```177178Run specific test cases (wildcards supported):179```180TESTS="*/testPersist" cmake --build cmake-build-relwithdebinfo -t test_model181```182183Run tests individually in separate processes (better isolation, per-suite parallelism):184```185cmake --build cmake-build-relwithdebinfo -j8 -t test_individually186cmake --build cmake-build-relwithdebinfo -j8 -t test_api_individually187```188189Run all test cases from all suites in a single CTest invocation (optimal cross-suite parallelism):190```191cmake --build cmake-build-relwithdebinfo -t test_all_parallel192```193194Pass extra flags to the Boost.Test runner:195```196TEST_FLAGS="--random" cmake --build cmake-build-relwithdebinfo -t test197```198199### Precommit (format + test)200201```202cmake --build cmake-build-relwithdebinfo -j8 -t precommit203```204Or: `./gradlew precommit`205206### Writing Tests207208- Test files are named `CClassNameTest.cc` and placed in `lib/<module>/unittest/` or `bin/<module>/unittest/`.209- Each test file uses `BOOST_AUTO_TEST_SUITE(CClassNameTest)` / `BOOST_AUTO_TEST_CASE(testMethodName)`.210- Use real classes over mocks wherever possible. Tests should reflect real-world usage.211- Every class should have a corresponding test suite; every public method should have a test.212- Test cases must be completely independent from one another — they may be run in parallel across separate processes, so they must not depend on execution order or share mutable state.213214## Formatting & Style215216Code is formatted with `clang-format` (LLVM-based style, 4-space indent). Run before committing:217```218cmake --build cmake-build-relwithdebinfo -t format219```220Or: `./gradlew format`221222The CI pipeline enforces formatting via the `check-style` step; PRs that fail formatting will not pass CI.223224The full coding standard is in `STYLEGUIDE.md`. Key points:225226### Naming Conventions227- Classes: `CClassName`, Structs: `SStructName`, Enums: `EEnumName`228- Member variables: `m_ClassMember`, `s_StructMember`229- Static members: `ms_ClassStatic`230- Methods: `methodName` (camelCase)231- Type aliases: `TTypeName` (e.g. `using TDoubleVec = std::vector<double>`)232- Constants: `CONSTANT_NAME`233- Non-boolean accessors: `clientId` (not `getClientId`)234- Boolean accessors: `isComplete` (not `complete`)235- Files: `CClassName.cc` / `CClassName.h`236237### Code Conventions238- Use `nullptr`, never `0` or `NULL`.239- No exceptions — use return codes for error handling. Catch third-party exceptions at the smallest scope.240- No `assert()`. No C-style casts. No macros unless unavoidable.241- Prefer smart pointers over raw pointers; prefer references over pointers.242- Scope member function calls with `this->`.243- Use `auto` when the type is obvious; avoid it when the type is unclear.244- Prefer `emplace_back` over `push_back`, range-based for loops, and uniform initializers.245- `override` must be used consistently; `virtual` must not appear alongside `override`.246247### File Layout248- Implementation files (`.cc`): own header first, then other ML headers, third-party headers, standard library headers.249- Group includes by library with blank lines between groups (clang-format will sort within groups).250- Use unnamed namespaces in `.cc` files for file-local helpers, not private class members.251- Forward-declare classes in headers rather than including their headers.252253### Documentation254- Doxygen comments (exclamation mark style: `//!`) are required for all header files and public/protected methods.255- Implementation files use regular C++ comments, not Doxygen.256- Focus comments on the "why", not the "what".257258## License Headers259260All source files must include the Elastic License 2.0 header. Copy from `copyright_code_header.txt` or any existing source file.261262## CI263264CI runs on **Buildkite** (`ml-cpp-pr-builds`). The pipeline builds and tests on all platforms (Linux x86_64, Linux aarch64, macOS aarch64, Windows x86_64) in both `RelWithDebInfo` and Debug configurations. It also runs:265- `clang-format` style validation266- Snyk security/license scanning267- Java integration tests against Elasticsearch268269Automatic backporting is handled by a GitHub Action (`.github/workflows/backport.yml`) — add version labels (e.g. `v9.3.0`) to a PR and a backport PR is created automatically when it merges.270271## Pull Requests272273- Title must be prefixed with `[ML]` (e.g. `[ML] Fix anomaly scoring edge case`).274- Label with `:ml` (mandatory), a type label (`>bug`, `>enhancement`, `>feature`, `>refactoring`, `>test`, `>docs`), and version labels for applicable releases.275- Squash-and-merge is the standard merge strategy; keep commits clean for review but don't squash manually.276- Backports start after merging to `main`. Add version labels to trigger automatic backport PRs.277278## Best Practices for Automation Agents279280- Always read existing code before editing to understand patterns and conventions.281- Never edit unrelated files; keep diffs tightly scoped.282- Run `clang-format` before presenting any code changes.283- Match the naming conventions exactly — the prefixes (`C`, `m_`, `ms_`, `T`, `E`) are strictly followed throughout the codebase.284- When adding new classes, follow the existing directory and namespace structure. Production code in `lib/foo/` uses namespace `ml::foo`.285- When adding tests, place them in the corresponding `unittest/` directory and register them in the `CMakeLists.txt`.286- Do not introduce new third-party dependencies without discussion.287- Do not add AI attribution trailers (e.g. `Co-Authored-By`) to commit messages.288- Commit messages should follow the `[ML] Summary of change` format.289- If unsure about a convention, check a nearby file for the established pattern — consistency with surrounding code is the highest priority.290291Stay aligned with `CONTRIBUTING.md`, `STYLEGUIDE.md`, and the `build-setup/` guides; this AGENTS file summarizes but does not replace those authoritative documents.292
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| elastic/ml-cpp.cursor/rules/ml-cpp-build-system.mdc · 157 | Cursor rules | buildtestarch | 76/100 | today | |
| elastic/ml-cpp.cursor/rules/ml-cpp-buildkite-ci.mdc · 157 | Cursor rules | buildstylearchsecurity+2 | 56/100 | today | |
| elastic/ml-cpp.cursor/rules/ml-cpp-ci-analytics.mdc · 157 | Cursor rules | buildgit | 54/100 | today | |
| elastic/ml-cpp.cursor/rules/ml-cpp-coding-conventions.mdc · 157 | Cursor rules | buildteststylegit+1 | 63/100 | today | |
| elastic/ml-cppCLAUDE.md · 157 | CLAUDE.md | buildteststylegit+1 | 71/100 | today |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| vllm-project/vllmAGENTS.md · 89k | AGENTS.md | setuptestlint-formatstyle+5 | 100/100 | 14 days ago | |
| netdata/netdatasrc/go/plugin/ibm.d/AGENTS.md · 80k | AGENTS.md | buildtestlint-formatarch+3 | 99/100 | today | |
| react/react-nativepackages/react-native-compatibility-check/AGENTS.md · 126k | AGENTS.md | testlint-formatstylearch+4 | 99/100 | 14 days ago | |
| ruvnet/RuViewAGENTS.md · 90k | AGENTS.md | teststylegitsecurity+3 | 97/100 | 14 days ago | |
| duckdb/duckdbAGENTS.md · 40k | AGENTS.md | buildtestlint-formatstyle+8 | 96/100 | 11 days ago | |
| dragonflydb/dragonflyAGENTS.md · 31k | AGENTS.md | setupbuildtestlint-format+10 | 96/100 | 13 days ago | |
| wshobson/agentsAGENTS.md · 39k | AGENTS.md | testlint-formatstylesecurity+2 | 93/100 | 14 days ago | |
| langflow-ai/langflowAGENTS.md · 153k | AGENTS.md | setuptestlint-formatstyle+10 | 89/100 | today |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/elastic-ml-cpp-agents)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.