Plugin Architecture Patterns
БесплатноБез исполняемых скриптовНе проверенChange plugin traits, typed registries, lifecycle or Alef Python bridges.
от xberg-io★ 9 642 звезды на GitHubОб этом скилле
Plugin Architecture & Registration
Plugin Types
| Type | Trait | Location |
|---|---|---|
| Document extractor (binding-facing) | DocumentExtractor: Plugin |
plugins/extractor/trait.rs |
| Document extractor (in-crate) | InternalDocumentExtractor: Plugin |
plugins/extractor/trait.rs |
| OCR backend | OcrBackend: Plugin |
plugins/ocr.rs (a file, not a directory) |
| Post processor | PostProcessor: Plugin |
plugins/processor/trait.rs |
| Validator | Validator: Plugin |
plugins/validator/trait.rs |
| Embedding backend | EmbeddingBackend: Plugin |
plugins/embedding.rs |
| Reranker backend | RerankerBackend: Plugin |
plugins/reranker.rs |
| Tokenizer backend | TokenizerBackend: Plugin |
plugins/tokenizer.rs |
| Renderer | Renderer: Plugin |
plugins/renderer.rs |
Plugin (plugins/traits.rs) is Send + Sync and requires name(); version(),
initialize(), shutdown(), description(), and author() have defaults. There is no
'static trait bound; registry-owned Arc<dyn Trait> supplies the necessary lifetime.
Native Rust extractors implement InternalDocumentExtractor
DocumentExtractor is the binding-facing surface. In-crate extractors implement
InternalDocumentExtractor and get DocumentExtractor from a blanket impl. Implementing
DocumentExtractor directly in this crate is the wrong layer.
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl InternalDocumentExtractor for MyExtractor {
async fn extract_content(&self, content: &[u8], mime_type: &str, config: &ExtractionConfig)
-> Result<InternalDocument> { /* ... */ }
fn supported_mime_types(&self) -> &[&str] { &["application/x-custom"] }
fn priority(&self) -> i32 { 50 }
}
extract_path has a default that reads the file and delegates to extract_content (and
errors without tokio-runtime).
Always use the two-arm cfg_attr form for async_trait. A bare #[async_trait] does not
match the trait declaration on wasm32.
The public trait has exactly four items — extract, supported_mime_types, priority,
can_handle. There is no as_sync_extractor; writing one is a compile error. WASM sync
support is the separate SyncExtractor trait — see wasm-constraints.
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 |
The registry selects the highest priority extractor for each MIME type. The ranges are
conventions over an unclamped i32; negative and values above 100 are representable. Equal
MIME and priority is a collision: the later registration replaces the earlier entry and
warns. Give competing plugins distinct priorities.
Registration
// crates/xberg/src/extractors/mod.rs -> register_default_extractors()
let registry = get_document_extractor_registry();
let mut registry = registry.write();
registry.register(Arc::new(MyExtractor::new()))?;
Feature-gate optional formats:
#[cfg(feature = "office")]
{
registry.register(Arc::new(DocxExtractor::new()))?;
registry.register(Arc::new(PptxExtractor::new()))?;
}
PostProcessor Pattern
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl PostProcessor for MyProcessor {
async fn process(&self, result: &mut ExtractedDocument, config: &ExtractionConfig)
-> Result<()> {
result.content = process_content(&result.content);
Ok(())
}
fn processing_stage(&self) -> ProcessingStage { ProcessingStage::Middle }
}
The enum is ProcessingStage and the accessor is processing_stage(). Stages:
Early (default) → Middle → Late. process takes &mut ExtractedDocument, not an owned
result.
Critical Rules
- All plugins MUST be
Send + Sync—Pluginrequires it. - In-crate extractors implement
InternalDocumentExtractor, neverDocumentExtractor. - Use the two-arm
cfg_attrasync_traitform on every plugin trait impl. - Feature-gate optional formats with
#[cfg(feature = "...")]at the registration site. - Initialization is lazy via
ensure_initialized()(extractors/mod.rs), called before first extraction. - Plugin names are kebab-case (e.g.
"pdf-extractor"). - A new extractor struct needs
#[cfg_attr(alef, alef(skip))]or the binding regen aborts — seealef-generated-bindings.
Registry and lifecycle invariants
- Eight plugin types have eight process-global typed registries in
plugins/registry/mod.rs. There is no universalPluginRegistry. - Registries use
Arc<parking_lot::RwLock<_>>. Their guards are not poisoned and.read()/.write()return guards directly. - Extractor lookup is
HashMap<mime, BTreeMap<priority, entry>>: exact MIME lookup is constant-time on the outer map; wildcard-f
Установить Plugin Architecture Patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл Plugin Architecture Patterns?
Change plugin traits, typed registries, lifecycle or Alef Python bridges.
Как установить скилл Plugin Architecture Patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Plugin Architecture Patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic