Agent Skillsxberg-io/xberg › wasm-constraints

wasm-constraints

GitHub

定义WASM构建约束,包括同步API、无Tokio、2MB HTML限制及尺寸优化。指导WASM目标开发、提取器适配及构建配置。

.ai-rulez/skills/wasm-constraints/SKILL.md xberg-io/xberg

Trigger Scenarios

构建WASM目标 添加或修改WASM兼容的提取器 调试WASM构建或运行时故障

Install

npx skills add xberg-io/xberg --skill wasm-constraints -g -y
More Options

Non-standard path

npx skills add https://github.com/xberg-io/xberg/tree/main/.ai-rulez/skills/wasm-constraints -g -y

Use without installing

npx skills use xberg-io/xberg@wasm-constraints

指定 Agent (Claude Code)

npx skills add xberg-io/xberg --skill wasm-constraints -a claude-code -g -y

安装 repo 全部 skill

npx skills add xberg-io/xberg --all -g -y

预览 repo 内 skill

npx skills add xberg-io/xberg --list

SKILL.md

Frontmatter
{
    "name": "wasm-constraints",
    "description": "WASM build constraints for the crates\/xberg-wasm crate — the wasm-target feature set, no-tokio sync-only internal APIs, the crate-private SyncExtractor trait, 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."
}

WASM Build Constraints

Overview

WASM target lives in crates/xberg-wasm/, built with wasm-bindgen over sync-only internal APIs. Note that crates/xberg-wasm/src/lib.rs is Alef-generated — do not hand-edit it.

Feature Flags

# crates/xberg/Cargo.toml
wasm-target = [
    "no-ort-target",
    "excel-wasm",
    "ocr-wasm",
    "layout-tract",
    "auto-rotate-tract",
    "ner-candle-wasm",
]

RT-DETR layout detection and PP-LCNet document orientation run through the pure-Rust tract engine; weights are streamed in from JS, never fetched by Rust (hf-hub/reqwest are native-only). Deliberately no tree-sitter: the 371-language grammar pack pushes the browser .wasm past jsDelivr's 50 MB per-file cap.

Critical Constraints

1. No Tokio Runtime

All operations must be synchronous internally. Use #[cfg(not(feature = "tokio-runtime"))] paths.

2. Internal Sync Extractor Required

Every WASM-compatible built-in extractor must implement SyncExtractor (crates/xberg/src/extractors/mod.rs). It is pub(crate), so only in-crate extractors can implement it — out-of-crate plugins cannot. This is not part of the public API; public callers still use extract / extract_batch.

impl SyncExtractor for MyExtractor {
    fn extract_sync(&self, content: &[u8], mime_type: &str, config: &ExtractionConfig)
        -> Result<InternalDocument> { /* sync implementation */ }
}

There is no as_sync_extractor() method on DocumentExtractor — do not write one.

3. HTML Size Limit

// crates/xberg/src/extraction/html/stack_management.rs
pub const MAX_HTML_SIZE_BYTES: usize = 2 * 1024 * 1024;  // 2 MB — stack constraint

Build Config

# crates/xberg-wasm/Cargo.toml
[lib]
crate-type = ["cdylib"]

# root Cargo.toml
[profile.release.package.xberg-wasm]
opt-level = "z"   # codegen-units = 1 comes from the global [profile.release]

API Pattern

The generated surface exposes async wasm-bindgen functions over sync internals:

#[wasm_bindgen]
pub async fn extract(input: JsValue, config: JsValue) -> Result<WasmExtractionResult, JsValue>

Functions can be async for JS ergonomics; extraction underneath is synchronous.

Critical Rules

  1. No tokio — all operations synchronous.
  2. Implement SyncExtractor for every WASM-compatible in-crate extractor.
  3. HTML capped at MAX_HTML_SIZE_BYTES (2 MB) due to stack constraints.
  4. Size optimization via opt-level = "z" on the package profile only.
  5. Gate WASM-specific code with #[cfg(target_arch = "wasm32")], and use the two-arm cfg_attr async_trait form on any plugin trait impl.

Version History

  • d8e4815 Current 2026-08-28 18:31

    修正了文档与实际代码不符的问题,移除了过时的类型和规则,更新了关于SyncExtractor的实现细节。

  • 531e0f7 2026-08-20 07:47

Same Skill Collection

.ai-rulez/skills/alef-generated-bindings/SKILL.md
.ai-rulez/skills/benchmark-workflow/SKILL.md
.ai-rulez/skills/chunking-embeddings/SKILL.md
.ai-rulez/skills/config-loading-precedence/SKILL.md
.ai-rulez/skills/crate-structure/SKILL.md
.ai-rulez/skills/extraction-pipeline-patterns/SKILL.md
.ai-rulez/skills/feature-flag-policy/SKILL.md
.ai-rulez/skills/mime-detection-routing/SKILL.md
.ai-rulez/skills/ocr-pipeline-and-quality/SKILL.md
.ai-rulez/skills/pdf-backends/SKILL.md
.ai-rulez/skills/plugin-architecture-patterns/SKILL.md
.ai-rulez/skills/polyrepo-boundaries/SKILL.md
.ai-rulez/skills/release-readiness/SKILL.md
.ai-rulez/skills/release-versioning/SKILL.md
.ai-rulez/skills/test-corpus/SKILL.md
.ai-rulez/skills/xberg-typescript-toolchain/SKILL.md
plugin/.ai-rulez/skills/batch-extraction/SKILL.md
plugin/.ai-rulez/skills/chunking/SKILL.md
plugin/.ai-rulez/skills/extracting-keywords/SKILL.md
plugin/.ai-rulez/skills/extracting-tables/SKILL.md
plugin/.ai-rulez/skills/extracting-with-ocr/SKILL.md
plugin/.ai-rulez/skills/picking-a-format/SKILL.md
plugin/.ai-rulez/skills/xberg/SKILL.md
plugin/.cursor-plugin/skills/batch-extraction/SKILL.md
plugin/.cursor-plugin/skills/chunking/SKILL.md
plugin/.cursor-plugin/skills/extracting-keywords/SKILL.md
plugin/.cursor-plugin/skills/extracting-tables/SKILL.md
plugin/.cursor-plugin/skills/extracting-with-ocr/SKILL.md
plugin/.cursor-plugin/skills/picking-a-format/SKILL.md
plugin/.cursor-plugin/skills/xberg/SKILL.md
plugin/skills/batch-extraction/SKILL.md
plugin/skills/chunking/SKILL.md
plugin/skills/extracting-keywords/SKILL.md
plugin/skills/extracting-tables/SKILL.md
plugin/skills/extracting-with-ocr/SKILL.md
plugin/skills/picking-a-format/SKILL.md
plugin/skills/xberg/SKILL.md
.ai-rulez/skills/api-server-mcp/SKILL.md
.ai-rulez/skills/format-specific-extraction/SKILL.md

Metadata

Files
0
Version
d8e4815
Hash
6b1af372
Indexed
2026-08-20 07:47

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-01 07:28
浙ICP备14020137号-1 $bản đồ khách truy cập$