ToughRADIUS AI Agent Development Guide
🤖 AI Agent Working Guidelines
🔍 Mandatory Requirement: Understand Existing Code Before Editing
Before touching any code, thoroughly inspect the relevant implementation and surrounding tests. Treat code search and context gathering as the very first step of every task.
Why This Matters
✅ Precise Targeting – Quickly locate existing implementations you can extend or reuse
✅ Architectural Awareness – Learn how modules collaborate before making changes
✅ Consistency – Mirror naming, data flow, and error-handling patterns already in place
✅ Risk Reduction – Avoid regressions caused by overlooking hidden dependencies
Recommended Search Workflow
Pinpoint the module: Identify packages, directories, or features involved (e.g.,
internal/radiusd/vendors).Use repository search tools: Combine
semantic_search,grep_search, andfile_searchwith precise keywords (function names, struct names, RFC identifiers, etc.).Read surrounding tests: Open the corresponding
*_test.go/ Playwright specs to understand expected behavior and edge cases.Record findings: Jot down key structs, helper functions, or patterns you must follow before implementing anything new.
Example Search Prompts
# Before adding new RADIUS vendor support
semantic_search "vendor attribute parsing" in internal/radiusd/vendors
grep_search "VendorCode" --include internal/radiusd/**
# Before adding new API endpoints
file_search "*/internal/adminapi/*routes*.go"
semantic_search "Echo middleware" in internal/webserver
# Before fixing authentication bugs
semantic_search "AuthError" in internal/radiusd
grep_search "app.GDB" --include internal/app/**
# Before large refactors
file_search "*radius_auth*.go"
list_code_usages AuthenticateUserIterative Exploration Pattern
Round 1: Macro View – Scan architecture docs (
docs/v9-architecture.md), service entry points, and top-level packages.Round 2: Detail Dive – Read concrete handler/service implementations plus related tests.
Round 3: Edge Cases – Inspect integration tests, benchmarks, or vendor-specific helpers to catch non-obvious behavior.
Always document the insights gained in your task notes or PR description so reviewers know which prior art influenced the change.
🧪 Mandatory Requirement: Continuous Verification
You MUST actively run tests throughout the development lifecycle.
Before changes: Run existing tests to establish a baseline.
During development: Run relevant tests frequently to catch regressions early.
After completion: Run the full test suite to ensure system integrity.
Never assume: "It should work" is not acceptable. Verify with
go test.
📝 Code is the Best Documentation Principle
Core Philosophy: Code IS Documentation, Documentation IS Code
We follow the "Standard Library Style" documentation approach. Just as the Go standard library is self-documenting, our codebase should be readable, understandable, and maintainable through comprehensive in-code comments, not separate Markdown files.
Correct Understanding of "Code Is Documentation":
✅ Documentation exists in the source code as comments
✅ Update comments in sync with every code change
✅ Full documentation is accessible through
go docand IDEs❌ Do not create separate Markdown documents for each module
❌ Do not generate documentation files after every development task
1. Write Documentation Directly in Code (Mandatory)
Every exported symbol (function, struct, interface, constant) must have a comprehensive comment in the source file that explains what it does, how to use it, and why it behaves that way.
Standard Library Style Checklist:
Package Comment: Every package must have a package-level comment explaining its purpose
Summary Sentence: The first sentence should be a concise summary that appears in
go docDetailed Description: Explain the behavior, side effects, and algorithm if necessary
Parameter Documentation: Use bulleted list format with types and constraints
Return Value Documentation: Clearly define what outputs are returned and when
Error Handling: Explicitly state what errors can be returned and under what conditions
Usage Examples: Provide code snippets in comments for complex APIs
Side Effects: Document any state changes, I/O operations, or concurrency implications
2. Documentation Examples
Example 1: Package-Level Documentation
Example 2: Function Documentation
Example 3: Struct Documentation
Example 4: Interface Documentation
3. Inline Comments for "Why" Not "What"
Use inline comments to explain why a specific implementation choice was made, especially for complex logic, workarounds, or optimizations. Do not explain what the code is doing if it's obvious from reading the code itself.
Good inline comments explain:
Non-obvious business logic
Performance optimizations
Workarounds for vendor quirks
Protocol-specific requirements
Edge cases and their handling
4. Vendor-Specific Code Must Document Protocol Details
Vendor-specific implementations must reference the authoritative specification and explain the data format, encoding rules, and any quirks or workarounds.
Documentation Strategy: Code-First Approach
When to Write In-Code Comments (Always Required):
Every code file should be self-documenting. Comments are NOT optional.
✅ Package comment - First file in each package must have package doc
✅ All exported symbols - Functions, methods, types, constants, variables
✅ Complex algorithms - Step-by-step explanation of non-trivial logic
✅ Non-obvious design decisions - Why this approach was chosen
✅ Protocol implementations - Reference RFC numbers, vendor specs
✅ Performance-critical code - Explain optimizations and trade-offs
✅ Error conditions - What errors can occur and why
✅ Concurrency guarantees - Thread-safety, locking, goroutine usage
✅ Side effects - Database writes, I/O, metric updates, logging
When to Create Separate Markdown Documentation (Rare):
Only create separate docs when in-code comments are insufficient for the target audience.
✅ Architecture Overview (
docs/architecture.md) - High-level system design for newcomers✅ User Guides (
README.md,docs/deployment.md) - For end users, not developers✅ API Contracts (
docs/api-spec.md) - For external integrators (REST API, gRPC)✅ Protocol References (
docs/rfcs/) - Standard specifications (read-only)✅ Migration Guides (
docs/migration-v8-to-v9.md) - Breaking changes between versions❌ NOT for module documentation - Put it in the code as package/function comments
❌ NOT for feature descriptions - Describe in code comments + Git commits
❌ NOT for work summaries - Use Git history and PR descriptions
When to Update Existing Docs (Only When Necessary):
✅ Public API changes → Update code comments first, then external API docs if needed
✅ Configuration options → Update example config files and inline comments
✅ Breaking changes → Update CHANGELOG.md + migration guide
✅ Deployment process → Update deployment docs
❌ Internal refactoring → Only update code comments, no separate doc needed
❌ Bug fixes → Git commit message is enough, no doc update
❌ Performance improvements → Update inline comments if algo changed
Documentation Verification:
Use go doc to verify your documentation is accessible:
Auto-Generated Documentation Rule (Strictly Prohibited)
AI Agent must NOT create separate documentation files unless explicitly requested.
The correct workflow is:
Write comprehensive in-code comments for all changes
Write clear Git commit messages explaining what and why
Update existing docs only if public API/config/deployment changed
Give brief completion confirmation in chat (1-2 sentences max)
Prohibited Actions:
❌ Auto-creating
SUMMARY.md,WORK_REPORT.md,DOCUMENTATION.mdafter task completion❌ Auto-creating module-specific doc files like
module-name-guide.md❌ Adding lengthy summaries in chat responses (multi-paragraph reports)
❌ Duplicating information that already exists in code comments or Git history
❌ Creating "documentation" as a separate deliverable for internal features
Allowed Actions:
✅ In-code comments - Always required, this IS the documentation
✅ Git commit messages - Explain what changed and why (Conventional Commits format)
✅ Brief completion note - 1-2 sentences confirming what was done
✅ Update existing docs - If public API, config, or deployment process changed
✅ Create docs when requested - User explicitly asks for a guide or tutorial
Correct Completion Response:
Incorrect Completion Response:
What Reviewers Should See:
Documentation Quality Standards
In-Code Documentation Must Be:
Clear - Use simple, plain language; avoid jargon unless explaining technical protocols
Complete - Document all parameters, returns, errors, side effects, concurrency
Practical - Include real-world usage examples for complex APIs
Accurate - Keep code and comments in sync (update comments when code changes)
Concise - Avoid redundant explanations of obvious code
Discoverable - Structured so
go docand IDEs can parse and display properly
Documentation Review Checklist:
Before submitting a PR, verify each exported symbol has:
Example: High-Quality In-Code Documentation
Golden Rules for "Code IS Documentation":
📝 In-code comments are THE documentation - Not supplementary, not optional
🎯 Write for readers - Future self, teammates, open-source contributors
🚫 No redundant Markdown files - Don't duplicate what's in code comments
✅ Git history is the changelog - Commit messages record what/when/why
🔍 Verify with
go doc- If it doesn't show up ingo doc, add more comments♻️ Update comments when code changes - Comments are part of the code, not separate
📚 Separate docs only for end users - Deployment guides, user manuals, API contracts
Anti-Pattern Recognition:
Core Development Principles
This project strictly follows these three core development principles. All code contributions must comply with these standards:
🧪 Test-Driven Development (TDD)
Mandatory Requirement: Write Tests First, Then Code
Before implementing any feature or fixing any bug, you MUST write a test case that reproduces the issue or defines the expected behavior.
Create Test File: If
internal/radiusd/auth.gois being modified, create/editinternal/radiusd/auth_test.go.Define Test Case: Write a test function
TestAuth_UserNotFoundthat asserts the expected failure.Run Test (Fail): Execute the test to confirm it fails (Red).
Implement Code: Write the minimum code necessary to pass the test.
Run Test (Pass): Execute the test to confirm it passes (Green).
Refactor: Clean up the code while keeping tests passing.
TDD Workflow
Red Phase - Write failing tests
Green Phase - Write minimal implementation to pass tests
Refactor Phase - Optimize code while keeping tests passing
🔄 Continuous Verification (Mandatory)
Do not wait until the end to run tests.
Every logical change should be followed by a test run.
If a test fails, stop and fix it immediately. Do not pile up changes on top of broken tests.
Use
go test ./...frequently to check for side effects in other packages.Verify compilation with
go build ./...to ensure no syntax errors or type mismatches were introduced.
Test Coverage Requirements
New feature code coverage must be ≥ 80%
Core RADIUS protocol module coverage must be ≥ 90%
Critical business logic must have integration tests
Test File Organization
Test Case Naming Convention
Table-Driven Tests
For multi-scenario testing, use table-driven approach:
🔄 GitHub Workflow
Mandatory Requirement: Follow Git Flow branching model and standard PR process
Branching Strategy
Standard Development Process
1. Create Feature Branch
2. TDD Loop Development
3. Commit Convention (Conventional Commits)
4. Create Pull Request
PR must include:
✅ All tests passing (
go test ./...)✅ Code coverage meets requirements
✅ Clear description and change summary
✅ Associated Issue number
✅ At least one code reviewer approval
PR Template:
5. Continuous Integration Checks
Each PR automatically triggers:
✅
go test ./...- Run all tests✅
go build- Ensure code compiles✅ Docker image build
✅ Code style checks
Release Process
📦 Minimum Viable Product (MVP) Principle
Mandatory Requirement: Each feature must be delivered in minimum viable units
MVP Design Method
Identify Core Value
❓ What problem does this feature solve?
❓ What is the simplest implementation?
❓ What is essential vs. nice-to-have?
Feature Breakdown Example
MVP Delivery Standards
Each MVP must be:
✅ Independently Usable - Does not depend on incomplete features
✅ Fully Tested - Coverage meets requirements
✅ Well Documented - API docs + usage guide
✅ Demonstrable - Can run and show value
✅ Rollback-Safe - Does not break existing functionality
MVP Practice Examples
Example 1: Adding RADIUS Vendor Support
Example 2: Performance Optimization
Complete Development Workflow Example
Scenario: Adding New RADIUS Vendor Support (Cisco)
Step 1: Create Issue (Requirements Analysis)
Step 2: TDD Development
Step 3: Commit Code
Step 4: Create Pull Request
Step 5: Code Review and Merge
Wait for CI to pass
Code review feedback
Fix issues, push updates
Merge to v9dev after approval
Step 6: Plan MVP-2
Create new Issue for next MVP
Repeat the above process
Quality Gates
All code must pass before merging:
✅ Automated Checks
✅ Code Review
✅ Documentation Requirements (Code-First Approach)
✅ MVP Acceptance
Common Anti-Patterns (Prohibited)
❌ Anti-Pattern 1: Exporting APIs Without Documentation
❌ Anti-Pattern 2: Committing Without Tests
❌ Anti-Pattern 3: Giant PRs
❌ Anti-Pattern 4: Implementation Before Tests
❌ Anti-Pattern 5: Skipping Code Review
❌ Anti-Pattern 6: Creating Redundant Documentation
❌ Anti-Pattern 7: Introducing CGO Dependencies
Tool Configuration
Local Development Environment Setup
Recommended VS Code Extensions
Go - Go language support
Go Test Explorer - Test visualization
Coverage Gutters - Coverage display
Conventional Commits - Commit convention helper
GitLens - Git enhancement
References
Remember: Quality over speed, Usable over perfect, Tests before code, Code is the documentation!
Documentation Hierarchy:
🥇 Code + Comprehensive Comments - First-class documentation
🥈 Git Commit History - Records what/why/when
🥉 Minimal Separate Docs - Only for architecture & external APIs
🚫 Technical Constraints
Mandatory Requirement: No CGO Dependencies
This project is designed to be cross-platform and easily deployable.
Strictly Forbidden: Introducing any library that requires
CGO_ENABLED=1.Database Drivers: Use pure Go drivers only (e.g.,
glebarez/sqliteinstead ofmattn/go-sqlite3).Build Flags: Always ensure
CGO_ENABLED=0is set in build scripts and CI configurations.
Last updated
Was this helpful?