AGENT SKILL

plugin-architecture-patterns

Plugin architecture, registration, and trait patterns

License 许可
Apache-2.0
最近更新
2026-11-15
Stars
★ 2
Forks
0

01 前言 Front Matter

name
plugin-architecture-patterns
priority
critical
description
Plugin architecture, registration, and trait patterns

03 SKILL.md 正文

Plugin Architecture & Registration

Plugin Types

Type Trait Location
Document Extractor DocumentExtractor: Plugin plugins/extractor/trait.rs
OCR Backend OcrBackend: Plugin plugins/ocr/trait.rs
Post Processor PostProcessor: Plugin plugins/processor/trait.rs
Validator Validator: Plugin plugins/validator/trait.rs

DocumentExtractor Implementation

use crate::plugins::{DocumentExtractor, Plugin};
use async_trait::async_trait;

pub struct MyExtractor;

impl Plugin for MyExtractor {
    fn name(&self) -> &str { "my-extractor" }
    fn version(&self) -> String { env!("CARGO_PKG_VERSION").to_string() }
}

#[async_trait]
impl DocumentExtractor for MyExtractor {
    async fn extract(&self, input: ExtractInput, config: &ExtractionConfig)
        -> Result<ExtractedDocument> { /* ... */ }

    fn supported_mime_types(&self) -> &[&str] { &["application/x-custom"] }
    fn priority(&self) -> i32 { 50 }

    // WASM support (optional)
    fn as_sync_extractor(&self) -> Option<&dyn SyncExtractor> { None }
}

Priority System

Range Use
0-25 Fallback/low-quality
26-49 Alternative extractors
50 Default (built-in)
51-75 Premium/enhanced
76-100 Specialized/high-priority

Registry selects highest priority extractor for each MIME type. Override built-ins with priority > 50.

Registration

// In extractors/mod.rs → register_default_extractors()
let registry = get_document_extractor_registry();
let mut registry = registry.write()
    .map_err(|e| XbergError::Other(format!("Registry lock poisoned: {}", e)))?;
registry.register(Arc::new(MyExtractor::new()))?;

Feature-Gated Registration

#[cfg(feature = "office")]
{
    registry.register(Arc::new(DocxExtractor::new()))?;
    registry.register(Arc::new(PptxExtractor::new()))?;
}

PostProcessor Pattern

impl PostProcessor for MyProcessor {
    async fn process(&self, result: &mut ExtractionResult, config: &ExtractionConfig)
        -> Result<()> {
        result.content = process_content(&result.content);
        Ok(())
    }
    fn stage(&self) -> ProcessorStage { ProcessorStage::Middle }
}

Stages: Early → Middle → Late. Failures isolated (don't block others).

Critical Rules

  1. All plugins MUST be Send + Sync
  2. Feature gate with #[cfg(feature = "...")] for optional formats
  3. Use #[async_trait] for DocumentExtractor
  4. Initialization via ensure_initialized() (lazy, called before first extraction)
  5. Plugin names: kebab-case (e.g., "pdf-extractor")

04 同仓库更多 Skills

jamon8888
jamon8888/hacienda-engine

impeccable

Use when the user wants to design, redesign, shape, critique, audit, polish, clarify, distill, harden, optimize, adapt, animate, colorize, extract, or otherwise improve a frontend interface. Covers websites, landing pages, dashboards, product UI, app shells, components, forms, settings, onboarding, and empty states. Handles UX review, visual hierarchy, information architecture, cognitive load, accessibility, performance, responsive behavior, theming, anti-patterns, typography, fonts, spacing, layout, alignment, color, motion, micro-interactions, UX copy, error states, edge cases, i18n, and reusable design systems or tokens. Also use for bland designs that need to become bolder or more delightful, loud designs that should become quieter, live browser iteration on UI elements, or ambitious visual effects that should feel technically extraordinary. Not for backend-only or non-UI tasks.

★ 2
jamon8888
jamon8888/hacienda-engine

wasm-constraints

WASM build constraints for the crates/xberg-wasm crate — the wasm-target feature set, no-tokio sync-only internal APIs, the mandatory SyncExtractor trait for WASM-compatible extractors, the 2 MB HTML size limit, size-optimized build config (opt-level="z"), and the async-wrapper/sync-internal API pattern. Load when building for wasm32, adding or modifying a WASM-compatible extractor, or debugging WASM build/runtime failures.

★ 2
jamon8888
jamon8888/hacienda-engine

release-versioning

How xberg versions are synced and released — Cargo.toml is the single source of truth, `task version:sync` propagates it to alef-managed binding manifests AND the integrations under integrations/, which are versioned and published in lockstep with core (including -rc.N). Load before bumping a version, editing the version-sync task, or touching an integration's version/xberg dependency.

★ 2
jamon8888
jamon8888/hacienda-engine

mime-detection-routing

MIME type detection and extractor routing in core/mime.rs and core/extractor/bytes.rs — the extension→EXT_TO_MIME→validate→registry→extractor flow, key detection functions, the 118+ case-insensitive extension map, priority-based registry selection, wildcard MIME families, and how to add a new MIME type. Load when adding a format, wiring an extractor to a MIME type, or debugging why a file routes to the wrong (or no) extractor.

★ 2
jamon8888
jamon8888/hacienda-engine

format-specific-extraction

Format-specific document extraction workflows

★ 2
jamon8888
jamon8888/hacienda-engine

feature-flag-policy

Cargo feature flags for crates/xberg — ORT-incompatible targets (WASM, Android x86_64 emulator), type-only and tract inference companion features, WASM/Android-safe variants, PDF backend, mutually-exclusive ORT variants, platform-conditional deps, aggregate feature sets, and build profiles. Load when adding, wiring, or debugging a Cargo feature, or when reasoning about what compiles on WASM/Android/Windows/macOS-intel targets.

★ 2