Agent Skills › xberg-io/xberg › alef-generated-bindings

alef-generated-bindings

GitHub

指导如何编辑和生成 Alef bindings,涵盖配置 alef.toml、执行代码再生与验证、处理多语言绑定及文档生成,确保 Rust 源码变更后正确同步各语言接口。

.ai-rulez/skills/alef-generated-bindings/SKILL.md xberg-io/xberg

Trigger Scenarios

需要生成或更新多语言 FFI 绑定 修改 Rust 源码后需重新生成 bindings 排查 bindings 生成失败或版本不同步问题

Install

npx skills add xberg-io/xberg --skill alef-generated-bindings -g -y
More Options

Non-standard path

npx skills add https://github.com/xberg-io/xberg/tree/main/.ai-rulez/skills/alef-generated-bindings -g -y

Use without installing

npx skills use xberg-io/xberg@alef-generated-bindings

指定 Agent (Claude Code)

npx skills add xberg-io/xberg --skill alef-generated-bindings -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": "alef-generated-bindings",
    "type": "Playbook",
    "paths": [
        "alef.toml",
        "packages\/**",
        "crates\/xberg-ffi\/**",
        "crates\/xberg-py\/**",
        "crates\/xberg-node\/**",
        "crates\/xberg-php\/**",
        "crates\/xberg-jni\/**",
        "crates\/xberg-wasm\/**",
        "crates\/xberg\/src\/extractors\/**",
        "crates\/xberg\/src\/plugins\/**"
    ],
    "title": "Alef Generated Bindings",
    "x-ai-rulez": {
        "id": "alef-generated-bindings",
        "kind": "skill",
        "metadata": {
            "name": "alef-generated-bindings"
        }
    },
    "description": "Edit Alef bindings: output paths, configuration, core regeneration and FFI JSON."
}

Alef-Generated Bindings

Xberg specifics on top of the shared Alef workflow skill (generic regenerate/verify/commit loop).

  • Check alef.toml before touching anything in packages/*/ or a binding crate.
  • Regenerate with alef all --clean --skip-compile --skip-snippet-validation (after mise run dart:format:context); it formats via poly. There is no alef:generate or alef:format task.
  • mise run alef:verify runs alef verify --exit-code.
  • Run alef docs directly to generate API documentation.
  • The alef:* namespace is exactly: verify, build, verify:readme-paths, verify:ffi-formats, verify:fields.

Freshness check

mise run alef:verify. A hand-rolled git diff over packages/ is under-scoped — generated output also lands in crates/xberg-py/, crates/xberg-php/, crates/xberg-jni/, crates/xberg-node/, crates/xberg-wasm/, crates/xberg-ffi/, packages/dart/rust/, packages/swift/rust/, and e2e/.

Each generated file carries an // alef:hash: header that alef verify recomputes; .alef/ (sources_hash.cache, hashes/) is a gitignored local cache, empty in a new worktree. Neither makes a generated file safe to hand-fix — a regen restores it. Fix alef.toml or the Rust source, then regenerate and re-verify.

Key alef.toml sections

  • [workspace], [workspace.sync] (version-sync extra_paths), [workspace.docs], [workspace.poly], [workspace.generate]
  • [[crates]] — the Rust source crate parsed for type/function extraction, plus [[crates.source_crates]]
  • [crates.<lang>] — one table per binding: python, node, ruby, php, elixir, wasm, ffi, go, java, dart, kotlin_android, jni, swift, csharp, zig (each carrying exclude_functions, target_dep_overrides, stubs, …)
  • [crates.e2e] — e2e generation (output = "e2e", [crates.e2e.call.overrides.<lang>])
  • [crates.readme] — README generation (template_dir = "templates/readme", [crates.readme.languages.<lang>])
  • [crates.exclude], [crates.output], [crates.custom_modules], [crates.publish]

There are no [crate], [languages.*], [e2e] or [readme] top-level tables, and alef.toml declares no rename mappings — the generated Go trait type is DocumentExtractor, unchanged.

Besides the per-language <lang>:e2e tasks, this repo has e2e:verify.

Core-side edits that break a regen

  • New extractor struct — needs #[cfg_attr(alef, alef(skip))] on the struct declaration, not the impl block. Without it the regen aborts globally and nothing regenerates, leaving the tree silently stale. Check this first when a regen dies. (Most modules in crates/xberg/src/extractors/ carry the attribute.)
  • Binding-facing types must not be #[non_exhaustive] — alef generates impl From<Mirror> for xberg::TheType with a struct literal in ~10 binding crates, and #[non_exhaustive] forbids that (E0639). Derive Default for forward-compat instead. Keep #[non_exhaustive] only on types listed in [crates.exclude].
  • A new enum variant on a binding-facing type breaks exhaustive matches across the generated binding crates.

Trait return types crossing the generated FFI bridge

The generated XbergOcrBackendBridge in crates/xberg-ffi/src/lib.rs marshals every trait method's return value through JSON (218 serde_json::from_str::<xberg::…> call sites today) and falls back to Default::default() on an uninitialised vtable slot, a failing host callback, or a null result. Whether a variant carries a payload is irrelevant.

Adding a method to a trait with a generated bridge means its return type needs Default + Serialize + Deserialize. Unit-only enums included.

crates/xberg-ffi is linted in CI only by cargo clippy --workspace at default features. Verify a change to it with the scoped cargo check -p xberg-ffi. That check rewrites crates/xberg-ffi/include/xberg.h and packages/go/include/xberg.h to match whatever feature set you invoked it with, which is usually not the committed one. Revert that churn rather than committing it.

Which alef answered

alef all runs whatever alef is first on PATH, not a cargo run against a sibling checkout; check alef --version against alef.toml alef_version before regenerating. A source fix in a sibling checkout has zero effect until it is installed. Generator fixes ship in order: land upstream → release alef → bump the pinned version → regen. Regenerating against a locally modified alef produces a tree the pinned version cannot reproduce.

Version History

  • 844bb91 Current 2026-11-03 09:36

    移除已废弃的 alef:generate/sync 等任务引用,明确使用 mise run 命令,细化 alef.toml 配置说明及核心侧编辑注意事项。

  • 3be78fd 2026-10-19 16:30

    迁移至 ai-rulez v5,使 AGENTS.md 成为规范入口,添加 pi preset 并调整 rumdl MD025 规则以适配 OKF 格式。

  • d8e4815 2026-08-28 18:30

    修正alef.toml结构(移除旧表头,新增crates.e2e/readme等),明确Go类型无重命名映射,更新freshness check逻辑及破坏性变更注意事项。

  • 531e0f7 2026-08-20 07:47

Same Skill Collection

.ai-rulez/skills/api-server-mcp/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/e2e-fixtures/SKILL.md
.ai-rulez/skills/extraction-pipeline-patterns/SKILL.md
.ai-rulez/skills/feature-flag-conventions/SKILL.md
.ai-rulez/skills/feature-flag-policy/SKILL.md
.ai-rulez/skills/format-specific-extraction/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/wasm-constraints/SKILL.md
.ai-rulez/skills/xberg-release/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-batch-extraction/SKILL.md
plugin/.ai-rulez/skills/xberg-chunking/SKILL.md
plugin/.ai-rulez/skills/xberg-extracting-keywords/SKILL.md
plugin/.ai-rulez/skills/xberg-extracting-tables/SKILL.md
plugin/.ai-rulez/skills/xberg-extracting-with-ocr/SKILL.md
plugin/.ai-rulez/skills/xberg-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-batch-extraction/SKILL.md
plugin/.cursor-plugin/skills/xberg-chunking/SKILL.md
plugin/.cursor-plugin/skills/xberg-extracting-keywords/SKILL.md
plugin/.cursor-plugin/skills/xberg-extracting-tables/SKILL.md
plugin/.cursor-plugin/skills/xberg-extracting-with-ocr/SKILL.md
plugin/.cursor-plugin/skills/xberg-picking-a-format/SKILL.md
plugin/.cursor-plugin/skills/xberg/SKILL.md
plugin/.opencode/skills/xberg-batch-extraction/SKILL.md
plugin/.opencode/skills/xberg-chunking/SKILL.md

Metadata

Files
0
Version
844bb91
Hash
c4e3d1d7
Indexed
2026-08-20 07:47

Home - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-11-04 18:04
浙ICP备14020137号-1