miyabi-core
Core utilities and shared functionality for the Miyabi framework.
Overview
miyabi-core provides essential utilities used across the Miyabi framework:
- Configuration Management: YAML/TOML/JSON config loading with environment variable support
- Structured Logging: Pretty/Compact/JSON log formats with tracing integration
- Retry Logic: Exponential backoff with configurable retry policies
- Documentation Generation: Rustdoc and README automation
- Security Audit: cargo-audit integration
- Git Utilities: Repository discovery, branch management, validation
- Project-Specific Rules:
.miyabirulessupport for custom coding standards
Features
🎯 Project-Specific Rules (.miyabirules)
Inspired by Cline's .clinerules - Define custom rules and agent preferences for your project.
The .miyabirules system allows you to:
- Define pattern-based code suggestions
- Configure agent-specific preferences (CodeGen, Review, Deployment, etc.)
- Enforce project-specific coding standards
- Filter rules by file extension
- Set severity levels (info, warning, error)
Quick Start:
# Copy the example file to your project root
# Or start with a simple template
Example .miyabirules file:
version: 1
rules:
- name: "Avoid unwrap"
pattern: ".unwrap()"
suggestion: "Use ? operator or expect() with a clear error message"
file_extensions:
severity: "warning"
enabled: true
- name: "Add documentation"
pattern: "pub fn"
suggestion: "Add /// documentation for public functions"
file_extensions:
severity: "info"
enabled: true
agent_preferences:
codegen:
style: "idiomatic"
error_handling: "thiserror"
review:
min_score: 80
clippy_strict: false
Installation
Add to your Cargo.toml:
[]
= { = "crates/miyabi-core" }
Usage
Configuration Management
use Config;
// Load configuration from YAML/TOML/JSON
let config = load?;
// Access configuration values
let api_key = config.get_string?;
let timeout = config.get_u64.unwrap_or;
Structured Logging
use ;
// Initialize logger with Pretty format
init_logger?;
// Use tracing macros
info!;
warn!;
error!;
Supported Formats:
Pretty- Human-readable with colorsCompact- Concise single-line outputJson- Structured JSON logs
Retry Logic
use ;
use Duration;
let config = RetryConfig ;
let result = retry_with_backoff.await?;
Project Rules (.miyabirules)
use ;
use PathBuf;
// Create loader for current directory
let loader = new;
// Load rules (returns None if .miyabirules not found)
let rules = loader.load?;
if let Some = rules
// Load or use default if not found
let rules = loader.load_or_default?;
Git Utilities
use ;
// Find Git repository root
let repo_root = find_git_root?;
// Check if in Git repository
if is_in_git_repo
Security Audit
use run_cargo_audit;
// Run cargo-audit and get vulnerabilities
let audit_result = run_cargo_audit.await?;
println!;
for vuln in audit_result.vulnerabilities
.miyabirules File Format
Schema
version: 1 # Required: Schema version (currently only 1 is supported)
rules: # Optional: Array of custom rules
- name: "Rule name" # Required: Human-readable name
pattern: "regex or substring" # Optional: Pattern to match
suggestion: "Suggestion text" # Required: What to suggest instead
file_extensions: # Optional: File types to apply to (empty = all)
severity: "info" # Optional: "info", "warning", or "error" (default: "info")
enabled: true # Optional: Whether rule is active (default: true)
agent_preferences: # Optional: Agent-specific settings
codegen: # Agent type (codegen, review, deployment, coordinator)
style: "idiomatic" # Code style preference
error_handling: "thiserror" # Error handling strategy
# Custom agent-specific settings can be added
settings: # Optional: Global settings
rust_edition: "2021"
max_line_length: 100
Rule Severity Levels
info: Informational suggestions (blue)warning: Important suggestions (yellow)error: Critical issues that should be fixed (red)
Agent Types
Supported agent types for agent_preferences:
codegen: Code generation preferences (style, error_handling, async_runtime, test_framework)review: Code review settings (min_score, clippy_strict, require_tests, require_docs)deployment: Deployment configuration (auto_deploy, target, run_tests)coordinator: Task coordination settings (max_tasks, prefer_parallel)
File Discovery
The RulesLoader searches for .miyabirules files in the following order:
.miyabirules(no extension).miyabirules.yaml.miyabirules.yml
The search starts from the specified directory and walks up the directory tree until a file is found or the root is reached.
Validation
Rules are validated when loaded:
- ✅ Version must be 1
- ✅ Rule names must be non-empty
- ✅ Suggestions must be non-empty
- ✅ Severity must be one of:
info,warning,error
Invalid configurations will return a RulesError::ValidationError.
Testing
# Run all tests
# Run with output
# Run specific module tests
Test Coverage:
- ✅ 11 unit tests (rules module)
- ✅ Configuration loading tests
- ✅ Logger initialization tests
- ✅ Retry logic tests
- ✅ Git utility tests
Examples
Complete .miyabirules Example
See .miyabirules.example for a comprehensive example with:
- 5 custom rules (async-trait, Result over Option, documentation, thiserror, avoid unwrap)
- Agent preferences for 4 agents (codegen, review, deployment, coordinator)
- Global settings (Rust edition, line length, tabs)
Simple .miyabirules Example
See .miyabirules.simple for a minimal starting point with:
- 2 basic rules
- Minimal agent preferences
API Reference
Core Modules
config- Configuration managementlogger- Structured logging setupretry- Retry logic with backoffrules- Project-specific rules (.miyabirules)git- Git repository utilitiessecurity- Security audit integrationdocumentation- Documentation generationcache- Caching utilities
Rules API
Main Types:
Key Methods:
Error Types:
Contributing
When adding new features to miyabi-core:
- Add comprehensive tests
- Update this README with usage examples
- Add Rustdoc comments to all public APIs
- Run
cargo clippyand fix all warnings - Run
cargo fmtto format code
Dependencies
[]
= { = "1.0", = ["derive"] }
= "1.0"
= "0.9"
= "2.0"
= "0.1"
= { = "0.3", = ["env-filter"] }
Development
Building
# Development build
# Release build
# Run clippy
# Format code
Project Structure
crates/miyabi-core/
├── src/
│ ├── cache.rs # Caching utilities
│ ├── config.rs # Configuration management
│ ├── documentation.rs # Documentation generation
│ ├── git.rs # Git utilities
│ ├── logger.rs # Structured logging
│ ├── retry.rs # Retry logic
│ ├── rules.rs # .miyabirules support (NEW)
│ ├── security.rs # Security audit
│ └── lib.rs # Public API
├── Cargo.toml
└── README.md
License
This project is part of the Miyabi framework.
Related Documentation
- Miyabi Project: ../../CLAUDE.md
- Entity-Relation Model: ../../docs/ENTITY_RELATION_MODEL.md
- Agent Operations: ../../docs/AGENT_OPERATIONS_MANUAL.md
miyabi-core - Core utilities for the Miyabi autonomous development framework
🤖 Generated with Claude Code