From 71e411640b6d5a5e93c7fdb9ca0cf823d748f7a5 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Thu, 7 May 2026 11:00:31 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Add=20AI=20agent=20instructions=20using=20t?= =?UTF-8?q?he=20AGENTS.md=20open=20standard=20Adds=20structured=20AI=20age?= =?UTF-8?q?nt=20documentation=20across=20the=20MongoDB=20Java=20Driver=20u?= =?UTF-8?q?sing=20the=20AGENTS.md=20convention=20=E2=80=94=20an=20open=20s?= =?UTF-8?q?tandard=20for=20providing=20codebase=20context=20to=20AI=20codi?= =?UTF-8?q?ng=20agents.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Root AGENTS.md with build commands, style rules, testing policy, API design guidelines, safety-critical code boundaries, and dependency rules - Per-module AGENTS.md files (bson, driver-core, driver-sync, etc.) with module-specific packages, dependencies, and patterns - CLAUDE.md files that reference AGENTS.md (for Claude Code compatibility) - `.agents/references/` for passive knowledge (contextually loaded): project-guide, style-reference, api-design, testing-guide, spec-tests - `.agents/skills/` for procedural workflows: evergreen (CI validation), sync-agents-docs (documentation sync checklist) - `scripts/symlink-claude-md.sh` for maintaining CLAUDE.md symlinks - References over skills for static knowledge: references are loaded contextually based on description relevance rather than requiring explicit invocation. This avoids bloating every conversation with all documentation while still surfacing it when needed. - Flat file layout for references (.agents/references/api-design.md) rather than directory-per-reference (.agents/references/api-design/REFERENCE.md): simpler structure; supplementary files use name-prefixing (e.g. testing-guide-examples.md) instead of subdirectories. - Markdown links (See [name](path)) rather than @ syntax for referencing from AGENTS.md: @ auto-includes file contents on every load, which defeats contextual loading. Links let agents follow them on demand. - Skills retained only for procedural workflows that have tool constraints (allowed-tools) or explicit trigger conditions (disable-model-invocation), not for passive knowledge lookup. JAVA-6143 --- .agents/references/api-design.md | 31 ++++++ .agents/references/project-guide.md | 63 +++++++++++ .agents/references/spec-tests.md | 40 +++++++ .agents/references/style-reference.md | 55 ++++++++++ .agents/references/testing-guide-examples.md | 92 ++++++++++++++++ .agents/references/testing-guide.md | 69 ++++++++++++ .agents/skills/evergreen/SKILL.md | 36 +++++++ .agents/skills/sync-agents-docs/SKILL.md | 27 +++++ .claude/skills | 1 + .gitignore | 6 ++ AGENTS.md | 104 ++++++++++++++++++ CLAUDE.md | 1 + README.md | 12 +++ bson-kotlin/AGENTS.md | 18 ++++ bson-kotlin/CLAUDE.md | 1 + bson-kotlinx/AGENTS.md | 19 ++++ bson-kotlinx/CLAUDE.md | 1 + bson-record-codec/AGENTS.md | 21 ++++ bson-record-codec/CLAUDE.md | 1 + bson-scala/AGENTS.md | 24 +++++ bson-scala/CLAUDE.md | 1 + bson/AGENTS.md | 24 +++++ bson/CLAUDE.md | 1 + buildSrc/AGENTS.md | 54 ++++++++++ buildSrc/CLAUDE.md | 1 + driver-benchmarks/AGENTS.md | 21 ++++ driver-benchmarks/CLAUDE.md | 1 + driver-core/AGENTS.md | 31 ++++++ driver-core/CLAUDE.md | 1 + driver-kotlin-coroutine/AGENTS.md | 19 ++++ driver-kotlin-coroutine/CLAUDE.md | 1 + driver-kotlin-extensions/AGENTS.md | 20 ++++ driver-kotlin-extensions/CLAUDE.md | 1 + driver-kotlin-sync/AGENTS.md | 19 ++++ driver-kotlin-sync/CLAUDE.md | 1 + driver-legacy/AGENTS.md | 22 ++++ driver-legacy/CLAUDE.md | 1 + driver-reactive-streams/AGENTS.md | 24 +++++ driver-reactive-streams/CLAUDE.md | 1 + driver-scala/AGENTS.md | 25 +++++ driver-scala/CLAUDE.md | 1 + driver-sync/AGENTS.md | 24 +++++ driver-sync/CLAUDE.md | 1 + gradle/AGENTS.md | 20 ++++ gradle/CLAUDE.md | 1 + mongodb-crypt/AGENTS.md | 26 +++++ mongodb-crypt/CLAUDE.md | 1 + scripts/symlink-claude-md.sh | 105 +++++++++++++++++++ testing/AGENTS.md | 11 ++ testing/CLAUDE.md | 1 + 50 files changed, 1082 insertions(+) create mode 100644 .agents/references/api-design.md create mode 100644 .agents/references/project-guide.md create mode 100644 .agents/references/spec-tests.md create mode 100644 .agents/references/style-reference.md create mode 100644 .agents/references/testing-guide-examples.md create mode 100644 .agents/references/testing-guide.md create mode 100644 .agents/skills/evergreen/SKILL.md create mode 100644 .agents/skills/sync-agents-docs/SKILL.md create mode 120000 .claude/skills create mode 100644 AGENTS.md create mode 100644 CLAUDE.md create mode 100644 bson-kotlin/AGENTS.md create mode 100644 bson-kotlin/CLAUDE.md create mode 100644 bson-kotlinx/AGENTS.md create mode 100644 bson-kotlinx/CLAUDE.md create mode 100644 bson-record-codec/AGENTS.md create mode 100644 bson-record-codec/CLAUDE.md create mode 100644 bson-scala/AGENTS.md create mode 100644 bson-scala/CLAUDE.md create mode 100644 bson/AGENTS.md create mode 100644 bson/CLAUDE.md create mode 100644 buildSrc/AGENTS.md create mode 100644 buildSrc/CLAUDE.md create mode 100644 driver-benchmarks/AGENTS.md create mode 100644 driver-benchmarks/CLAUDE.md create mode 100644 driver-core/AGENTS.md create mode 100644 driver-core/CLAUDE.md create mode 100644 driver-kotlin-coroutine/AGENTS.md create mode 100644 driver-kotlin-coroutine/CLAUDE.md create mode 100644 driver-kotlin-extensions/AGENTS.md create mode 100644 driver-kotlin-extensions/CLAUDE.md create mode 100644 driver-kotlin-sync/AGENTS.md create mode 100644 driver-kotlin-sync/CLAUDE.md create mode 100644 driver-legacy/AGENTS.md create mode 100644 driver-legacy/CLAUDE.md create mode 100644 driver-reactive-streams/AGENTS.md create mode 100644 driver-reactive-streams/CLAUDE.md create mode 100644 driver-scala/AGENTS.md create mode 100644 driver-scala/CLAUDE.md create mode 100644 driver-sync/AGENTS.md create mode 100644 driver-sync/CLAUDE.md create mode 100644 gradle/AGENTS.md create mode 100644 gradle/CLAUDE.md create mode 100644 mongodb-crypt/AGENTS.md create mode 100644 mongodb-crypt/CLAUDE.md create mode 100755 scripts/symlink-claude-md.sh create mode 100644 testing/AGENTS.md create mode 100644 testing/CLAUDE.md diff --git a/.agents/references/api-design.md b/.agents/references/api-design.md new file mode 100644 index 00000000000..23e89ebe457 --- /dev/null +++ b/.agents/references/api-design.md @@ -0,0 +1,31 @@ +--- +name: api-design +description: API stability annotations, design principles, and patterns for the MongoDB Java Driver. Use when adding or modifying public API surface — new classes, methods, interfaces, or changing method signatures. +--- +# API Design + +## API Stability Annotations + +- `@Alpha` — Early development, may be removed. + Not recommended for production use. +- `@Beta` — Subject to change or removal. + It's not recommended for Libraries to depend on these APIs. +- `@Evolving` — May add abstract methods in future releases. + Safe to use, but implementing/extending bears upgrade risk. +- `@Sealed` — Must not be extended or implemented by consumers. + Safe to use, but not to subclass. +- `@Deprecated` — Supported until next major release but should be migrated away from. + +## Design Principles + +- **Deep modules:** Prefer simple interfaces with powerful implementations over shallow wrappers. +- **Information hiding:** Bury complexity behind simple interfaces. +- **Pull complexity downward:** Make the implementer work harder so callers work less. +- **General-purpose over special-case:** Fewer flexible methods over many specialized ones. +- **Define errors out of existence:** Design APIs so errors cannot happen rather than detecting and handling them. + +## Key Patterns + +- Static factory methods: `Filters.eq()`, `Updates.set()`, `Aggregates.match()` +- Fluent builders: `MongoClientSettings.builder()` is the primary entry point +- Abstract core with pluggable transports diff --git a/.agents/references/project-guide.md b/.agents/references/project-guide.md new file mode 100644 index 00000000000..a068414426e --- /dev/null +++ b/.agents/references/project-guide.md @@ -0,0 +1,63 @@ +--- +name: project-guide +description: Project structure, dependency graph, and guide for finding the right project to work in. Use when starting a task and unsure which project owns the relevant code, or when you need to understand cross-project dependencies. +--- +# Project Guide + +## Project Structure + +| Project | Purpose | +| --- | --- | +| `bson` | BSON library (core serialization) | +| `bson-kotlin` | Kotlin BSON extensions | +| `bson-kotlinx` | Kotlin serialization BSON codec | +| `bson-record-codec` | Java record codec support | +| `bson-scala` | Scala BSON extensions | +| `driver-core` | Core driver internals (connections, protocol, operations) | +| `driver-sync` | Synchronous Java driver | +| `driver-legacy` | Legacy MongoDB Java driver API | +| `driver-reactive-streams` | Reactive Streams driver | +| `driver-kotlin-coroutine` | Kotlin Coroutines driver | +| `driver-kotlin-extensions` | Kotlin driver extensions | +| `driver-kotlin-sync` | Kotlin synchronous driver | +| `driver-scala` | Scala driver | +| `mongodb-crypt` | Client-side field-level encryption | +| `bom` | Bill of Materials for dependency management | +| `testing` | Shared test resources and MongoDB specifications | +| `buildSrc` | Gradle convention plugins and build infrastructure | +| `driver-benchmarks` | JMH and custom performance benchmarks (not published) | +| `driver-lambda` | AWS Lambda test application (not published) | +| `graalvm-native-image-app` | GraalVM Native Image compatibility testing (not published) | + +## Dependency Graph (simplified) + +``` +bson + ├── bson-kotlin + ├── bson-kotlinx + ├── bson-record-codec + ├── bson-scala + └── driver-core + ├── driver-sync + │ ├── driver-legacy + │ ├── driver-kotlin-sync + │ └── driver-lambda + ├── driver-reactive-streams + │ ├── driver-kotlin-coroutine + │ └── driver-scala + └── driver-kotlin-extensions +``` + +## Finding the Right Module + +- **BSON serialization/codecs:** `bson` (or `bson-kotlin`/`bson-kotlinx`/`bson-scala` for language-specific) +- **Query builders, filters, aggregates:** `driver-core` (`com.mongodb.client.model`) +- **Sync Java API:** `driver-sync` +- **Reactive API:** `driver-reactive-streams` +- **Kotlin coroutines:** `driver-kotlin-coroutine` +- **Kotlin DSL builders:** `driver-kotlin-extensions` +- **Scala driver:** `driver-scala` +- **Connection, protocol, auth internals:** `driver-core` (`com.mongodb.internal.*`) +- **Build plugins, formatting, test infra:** `buildSrc` + +Each module has its own `AGENTS.md` with module-specific packages, patterns, and notes. diff --git a/.agents/references/spec-tests.md b/.agents/references/spec-tests.md new file mode 100644 index 00000000000..5ba9041cfbc --- /dev/null +++ b/.agents/references/spec-tests.md @@ -0,0 +1,40 @@ +--- +name: spec-tests +description: How to work with MongoDB specification tests — structure, rules, and adding new spec test support. Use when implementing or modifying behavior defined by the MongoDB Driver Specifications. +--- +# MongoDB Specification Tests + +## Overview + +The driver implements the [MongoDB Driver Specifications](https://github.com/mongodb/specifications). +Specification test data files live in `testing/resources/specifications/` — a git submodule. + +## Rules + +- **Do not modify spec test data files** (JSON/YAML in `testing/resources/specifications/`) — managed upstream +- Test runners (Java code) may be modified to fix bugs or add support for new spec tests +- Update the submodule via `git submodule update` + +## Structure + +Spec test data is organized by specification area: + +- CRUD, SDAM, auth, CSFLE, retryable operations, and more +- Each spec area has JSON/YAML test data files defining inputs and expected outputs +- Driver test runners parse these files and execute against the driver + +## Test Data Location + +``` +testing/ + resources/ + specifications/ # Git submodule — do not edit directly + logback-test.xml # Shared logback configuration for tests +``` + +## Adding Spec Test Support + +1. Check `testing/resources/specifications/` for the relevant spec test data +2. Find existing test runners in the module (look for `*SpecificationTest*` or similar) +3. Extend existing patterns — each module handles spec tests slightly differently +4. Ensure tests run with `./gradlew check` or the module’s test task diff --git a/.agents/references/style-reference.md b/.agents/references/style-reference.md new file mode 100644 index 00000000000..fa9adfe85f2 --- /dev/null +++ b/.agents/references/style-reference.md @@ -0,0 +1,55 @@ +--- +name: style-reference +description: Detailed code style rules for Java, Kotlin, Scala, and Groovy in the MongoDB Java Driver. Use when you need specific formatting rules beyond the basics in root AGENTS.md — e.g., line length, import ordering, brace style. +--- +# Style Reference + +## Java Style Rules + +- **Max line length:** 140 characters +- **Indentation:** 4 spaces (no tabs) +- **Line endings:** LF (Unix) +- **Charset:** UTF-8 +- **Star imports:** Prohibited (AvoidStarImport) +- **Final parameters:** Required (FinalParameters checkstyle rule) +- **Braces:** Required for all control structures (NeedBraces) +- **Else placement:** `} else {` on the same line (Palantir Java Format default) +- **Copyright header:** Every Java / Kotlin / Scala file must contain `Copyright 2008-present MongoDB, Inc.` +- **Formatter:** Palantir Java Format + +## Kotlin Style Rules + +- **Formatter:** ktfmt dropbox style, max width 120 +- **Static analysis:** detekt + +## Scala Style Rules + +- **Formatter:** scalafmt +- **Supported versions:** 2.11, 2.12, 2.13, 3 (default: 2.13) + +## Groovy Style Rules + +- **Static analysis:** CodeNarc + +## Javadoc / KDoc / Scaladoc + +- All public classes and interfaces **must** have class-level Javadoc (enforced by checkstyle) +- Public methods should have Javadoc with `@param`, `@return`, and `@since` tags +- Use `@since X.Y` to indicate the version when the API was introduced +- Use `@mongodb.driver.manual