AGENT SKILL
napi-extract
Extract logic from a crates/pi-natives N-API module into an ordinary Rust library crate, leaving a thin N-API adapter so TypeScript callers keep working. Use when porting a pi-natives module (sixel, pdf, grep, text, tokens, etc.) for direct use by the Rust app (rust-agent / harvest-omp).
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- napi-extract
- description
- Extract logic from a crates/pi-natives N-API module into an ordinary Rust library crate, leaving a thin N-API adapter so TypeScript callers keep working. Use when porting a pi-natives module (sixel, pdf, grep, text, tokens, etc.) for direct use by the Rust app (rust-agent / harvest-omp).
03 SKILL.md 正文
Extract a pi-natives module
Reference implementation: crates/pi-natives/src/html.rs → crates/harvest-media/src/html.rs (commit 6253f50).
- Read the module in
crates/pi-natives/src/<mod>.rs, its TS callers (grep -rn "<exportName>" packages/), and the generated declarations inpackages/natives. - Move the logic into the target crate (
harvest-media,harvest-tui,harvest-runtime,harvest-tokenizer, or a newcrates/harvest-<area>) with a plain Rust API: owned/borrowed Rust types, a typed error enum, options struct withDefault. Nonapitypes in the library. - Add explicit input/size/allocation bounds before work; check dependency types in
~/.cargo/registryrather than guessing (e.g.image::Limitsis non-exhaustive and not strict for all decoders). - Rewrite the N-API function as an adapter only: convert JS inputs (
crate::js::into_string), call the library insidetask::blocking(...), map errors withError::from_reason. Preserve the existing JS-facing signature, defaults and error text exactly. - Re-export from
rust-agent(harvest_omp::<area>) if the Rust app needs it. - Wire: workspace
Cargo.toml,Cargo.lock,pi-natives/Cargo.tomldependency, BazelBUILD.bazeltargets, Rust CI package list. - Verify: Rust tests (
cargo xtask test -p <crate>),bun run build:native, then diff generated bindings — revert the four known unrelated audio declaration lines (AudioCapture.droppedChunks,AudioPlayback.queuedSamples+ comments) if they appear. Compare old vs new addon output on an oracle input set; run focused TS consumer tests. - Continue with
/rust-migration-slicesteps 5–7 (ledger, docs, commit).
04 同仓库更多 Skills
greet
A greeting skill for testing
★ 3
valid-skill
A valid skill for testing purposes.
★ 3
unknown-field
A skill with an unknown frontmatter field.
★ 3
no-frontmatter
暂无简介
★ 3
child-skill
A nested skill in a subdirectory.
★ 3
different-name
A skill with a name that doesn't match the directory.
★ 3