Repository navigation
Authoring Plugins in Rust
Jon edited this page Sep 5, 2026
·
1 revision
Rust plugins are compiled native binaries placed in ~/.ash/plugins/. They offer maximum performance, memory safety, and zero runtime dependencies.
-
AI Capability Discovery (
--ai-docs):- Parse
--ai-docsinstd::env::args()and print formatted JSON.
- Parse
-
Standard CLI Flags (
--version,--help):- Return standard version strings and usage instructions.
-
Structured Logging Integration:
- Check
std::env::var("ASH_LOG_FILE"). If present, append JSON or text logs respectingASH_LOG_FORMATandASH_VERBOSE, tagging log entries with anEIDattribute.
- Check
-
Clean Exit Codes:
- Return exit code
0on success and non-zero on error.
- Return exit code
use std::env;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::Path;
const VERSION: &str = "1.0.0";
const PLUGIN_NAME: &str = "my_rust_plugin";
fn print_ai_docs() {
println!(r#"{{
"Capabilities": ["Perform rust-powered tasks."],
"Arguments": {{
"--ai-docs": "Print AI docs",
"--version": "Print version",
"--help": "Print help"
}},
"Return format": {{
"status": "success or error",
"result": "computed data"
}}
}}"#);
}
fn log_event(level: &str, msg: &str, eid: &str) {
if let Ok(log_file) = env::var("ASH_LOG_FILE") {
if let Ok(mut file) = OpenOptions::new().create(true).append(true).open(Path::new(&log_file)) {
let _ = writeln!(file, r#"{{"level":"{}","plugin":"{}","message":"{}","EID":"{}"}}"#, level, PLUGIN_NAME, msg, eid);
}
}
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
if let Some(arg) = args.first() {
match arg.as_str() {
"--ai-docs" => { print_ai_docs(); return; }
"--version" | "-v" => { println!("{} {}", PLUGIN_NAME, VERSION); return; }
"--help" | "-h" => { println!("Usage: {} [options]", PLUGIN_NAME); return; }
_ => {}
}
}
log_event("info", "executing rust plugin", "rPlg01a");
println!("Hello from Rust plugin!");
}internal/app/ash_bootstrap/plugins_src/my_rust_plugin/
├── Cargo.toml
├── Makefile
├── README.md
└── src/
└── main.rs
Example Makefile:
PLUGIN_NAME := my_rust_plugin
BUILD_DIR ?= ../../../../../bin/plugins
OUTPUT_PATH ?= $(BUILD_DIR)/$(PLUGIN_NAME)
.PHONY: all build test lint clean
all: build
build:
@mkdir -p "$(BUILD_DIR)"
@cargo build --release
@cp target/release/$(PLUGIN_NAME) "$(OUTPUT_PATH)"
test:
@cargo test
lint:
@cargo check
clean:
@cargo clean
@rm -f "$(OUTPUT_PATH)"