agentleFS
dromaradromara/mica-mqtt/AGENTS.md

mica-mqtt

AGENTS.md495 starsChanged 7 months agoApache-2.0View on GitHub

This file provides context, commands, and coding standards for AI agents to effectively and safely modify this codebase. --> Note: Always run tests after modifications to ensure no regressions.

  • 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 32,671 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 repositoryOne other file it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

21 rules. About 1 is common, 11 are distinctive, and 9 are very specific to this project.

  • ≈1

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Indentation: Use TABS (not spaces).

    line 46
  2. Very specific:

    Use the Builder pattern manually if complex object creation is needed (see MqttWillMessage).

    line 60
  3. Distinctive:

    All new Java files must include the Apache License 2.0 header:

    line 65
  4. Distinctive:

    Use SLF4J for logging.

    line 86
  5. Very specific:

    Use appropriate log levels: debug for verbose info, info for important events, warn/error for issues.

    line 88
  6. Very specific:

    Avoid excessive info logging in high-frequency code paths (e.g., message handling).

    line 89
  7. Very specific:

    Avoid wildcard imports (import java.util.*;).

    line 92
  8. Distinctive:

    Use import statements instead of fully qualified class names in code.

    line 97
  9. Very specific:

    Use specific exception types rather than generic Exception.

    line 100
  10. Distinctive:

    Avoid swallowing exceptions silently unless explicitly intended.

    line 102
  11. Distinctive:

    Use primitive types where possible for performance.

    line 114
  12. Very specific:

    Use List, Map, Set interfaces rather than concrete implementations in method signatures.

    line 115
  13. Very specific:

    Serialization: Use the MqttSerializer interface for payload serialization.

    line 122
  14. Distinctive:

    Write unit tests for new logic using JUnit (Jupiter).

    line 137
  15. Very specific:

    Place tests in the src/test/java directory corresponding to the package structure.

    line 138
  16. Distinctive:

    No Assumptions: Always verify file existence and content before editing.

    line 144
  17. Distinctive:

    Minimal Changes: Only modify what is necessary to fulfill the request.

    line 145
  18. Distinctive:

    Preserve Style: If you see a file using a specific style (even if it contradicts general rules), follow the file's local style (except for …

    line 146
  19. Common:

    Safety: Do not commit secrets or breaking changes without user confirmation.

    line 147
  20. Very specific:

    Verification: After making changes, always run mvn compile to verify the code compiles.

    line 148
  21. Distinctive:

    Testing: Run relevant tests after modifications to ensure no regressions.

    line 149

≈ “Common” is an estimate: at least 1 in 5 of the 41,581 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md
<!-- AGENTS.md - Instructions for AI Agents working on mica-mqtt This file provides context, commands, and coding standards for AI agents to effectively and safely modify this codebase. -->

mica-mqtt Agent Guidelines

1. Environment & Build

  • Language: Java 8 (<java.version>1.8</java.version>).
  • Build Tool: Maven 3.x.
  • Project Structure: Multi-module Maven project.

Modules

ModuleDescription
mica-mqtt-codecMQTT protocol codec
mica-mqtt-commonCommon utilities and models
mica-mqtt-coreCore server/client interfaces
mica-mqtt-serverMQTT broker implementation
mica-mqtt-clientMQTT client implementation
mica-mqtt-brokerEnhanced broker with cluster support (t-io based)
starterSpring Boot, Solon, JFinal integrations
exampleUsage examples

Key Commands

ActionCommand
Build Projectmvn clean install
Run All Testsmvn test
Run Single Test Classmvn -Dtest=TargetTestClass test
Run Single Test Methodmvn -Dtest=TargetTestClass#methodName test
Compile Onlymvn compile
Packagemvn package -DskipTests
Run Tests in Specific Modulecd mica-mqtt-broker && mvn test

Note: Always run tests after modifications to ensure no regressions.

2. Code Style & Conventions

Formatting

  • Indentation: Use TABS (not spaces).
  • Encoding: UTF-8.
  • Line Endings: LF (Unix-style).

Naming

  • Classes: PascalCase (e.g., MqttServer, MqttConnectStatusListener).
  • Methods/Variables: camelCase (e.g., publishMessage, clientId).
  • Constants: UPPER_SNAKE_CASE (e.g., MAX_MESSAGE_SIZE).
  • Packages: lowercase (e.g., org.dromara.mica.mqtt.core).

Lombok Usage

  • Core Modules (mica-mqtt-server, mica-mqtt-client, mica-mqtt-common, mica-mqtt-codec, mica-mqtt-broker):
    • DO NOT USE LOMBOK.
    • Manually implement getters, setters, equals, hashCode, toString, and constructors.
    • Use the Builder pattern manually if complex object creation is needed (see MqttWillMessage).
  • Starter/Example Modules:
    • Lombok (e.g., @Data) is acceptable in these layers but prefer consistency with existing code.

License Header

All new Java files must include the Apache License 2.0 header:

/*
 * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & dreamlu.net).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Logging

  • Use SLF4J for logging.
  • private static final Logger logger = LoggerFactory.getLogger(ClassName.class);
  • Use appropriate log levels: debug for verbose info, info for important events, warn/error for issues.
  • Avoid excessive info logging in high-frequency code paths (e.g., message handling).

Imports

  • Avoid wildcard imports (import java.util.*;).
  • Group imports in this order:
    1. Project specific imports (org.dromara...)
    2. Third-party libraries (org.slf4j..., org.tio...)
    3. Standard Java (java..., javax...)
  • Use import statements instead of fully qualified class names in code.

Error Handling

  • Use specific exception types rather than generic Exception.
  • Log exceptions with appropriate context before rethrowing or handling.
  • Avoid swallowing exceptions silently unless explicitly intended.
  • Example:
    try {
        // code
    } catch (IOException e) {
        logger.error("Failed to process message from node: {}", nodeId, e);
        return;
    }

Types

  • Use primitive types where possible for performance.
  • Use List, Map, Set interfaces rather than concrete implementations in method signatures.
  • Initialize collections with appropriate implementations (e.g., ArrayList, HashMap, HashSet).

3. Architecture & Patterns

  • Asynchronous IO: The project is built on t-io. Be careful with blocking operations in IO threads.
  • Thread Safety: Core classes like MqttServer are often accessed concurrently. Ensure thread safety for shared state.
  • Serialization: Use the MqttSerializer interface for payload serialization.
  • Design Patterns:
    • Builder: Used for complex configuration/message objects (e.g., MqttPublishMessage.builder()).
    • Listener: Heavily used for events (MqttProtocolListener, IMqttMessageListener).
    • Decorator: Used in mica-mqtt-broker for session management (ClusterMqttSessionManager wraps IMqttSessionManager).

Cluster Module (mica-mqtt-broker)

  • Built on t-io cluster for node-to-node communication.
  • Uses MqttBroker.create() as entry point for cluster brokers.
  • Fluent API for configuration (MqttClusterConfig.enabled(true).clusterPort(9001)).
  • Cluster messages inherit from ClusterMessage base class.
  • Session state is synchronized across nodes via ClusterMqttSessionManager.

4. Testing

  • Write unit tests for new logic using JUnit (Jupiter).
  • Place tests in the src/test/java directory corresponding to the package structure.
  • Mock external dependencies where possible to keep tests fast.
  • Cluster integration tests may have Windows-specific cleanup issues with t-io; focus on test assertions passing.

5. Agent Behavior Rules

  • No Assumptions: Always verify file existence and content before editing.
  • Minimal Changes: Only modify what is necessary to fulfill the request.
  • Preserve Style: If you see a file using a specific style (even if it contradicts general rules), follow the file's local style (except for clearly erroneous logic).
  • Safety: Do not commit secrets or breaking changes without user confirmation.
  • Verification: After making changes, always run mvn compile to verify the code compiles.
  • Testing: Run relevant tests after modifications to ensure no regressions.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.