跳转到内容

快速入门

本指南将带你走完完整的 Rotifer 基因生命周期——从项目初始化到运行多基因 Agent 管道。

  • Node.js >= 20.0.0
  • npm >= 9
  • (可选)Rust 工具链 — 仅在使用 NAPI 桥接进行 Native WASM 编译时需要

v0.3 新功能: rotifer compile 现在自动将 TypeScript 基因编译为 Native WASM(通过 Javy)。无需额外的 Rust/WASM 工具链!

Terminal window
npm install -g @rotifer/playground

或通过 npx 直接使用:

Terminal window
npx @rotifer/playground init my-project
Terminal window
rotifer init my-project
cd my-project

项目将包含五个 Genesis 基因,已在活跃的 Arena 中预排名:

my-project/
├── rotifer.config.json
├── genes/
│ ├── genesis-web-search/
│ ├── genesis-web-search-lite/
│ ├── genesis-file-read/
│ ├── genesis-code-format/
│ └── genesis-l0-constraint/
└── .rotifer/
└── arena.db
Terminal window
rotifer scan genes/

扫描器检测已导出的函数并报告其与基因标准的兼容性。

创建一个简单函数:

Terminal window
mkdir -p genes/hello-world

编写 genes/hello-world/index.ts

interface Input { name: string; }
interface Output { greeting: string; }
export async function express(input: Input): Promise<Output> {
return {
greeting: `你好,${input.name}!欢迎来到 Rotifer Protocol。`,
};
}

包装它:

Terminal window
rotifer wrap hello-world

这将生成 phenotype.json — 基因的元数据,描述其领域、模式和保真度。

Terminal window
rotifer test hello-world

测试运行器会动态导入 express(),从 schema 生成输入,验证输出,并在存在编译后的 WASM 时验证 IR 完整性。

Terminal window
rotifer compile hello-world

v0.3:自动 TS→WASM 编译。 如果基因目录中有 index.tsindex.js 文件且没有预编译的 gene.wasm,编译器会自动运行:

index.ts → esbuild(类型剥离)→ Javy(QuickJS→WASM)→ Rotifer IR(自定义段注入)

你也可以直接提供预编译的 WASM:

Terminal window
rotifer compile hello-world --wasm path/to/hello.wasm

IR 编译器会将 Rotifer 自定义段(版本、表型、约束、计量)注入 WASM 二进制。

Terminal window
rotifer arena submit hello-world

Arena 运行准入评估:测试基因,计算适应度 F(g) 和安全分 V(g),两者通过阈值后注册。

Terminal window
rotifer arena list

按领域过滤:

Terminal window
rotifer arena list --domain search

Agent 组装一个基因组 — 从 Arena 中选择基因的组合。

Terminal window
rotifer agent create greeter-bot --genes hello-world genesis-code-format

或从某个领域自动选择排名靠前的基因:

Terminal window
rotifer agent create search-agent --domain search --top 2

执行基因组作为顺序管道——每个基因的输出作为下一个基因的输入:

Terminal window
rotifer agent run greeter-bot --input '{"name":"World"}'

使用 --verbose 查看每步的中间输入和输出。

使用 GitHub 登录,发布你的基因,让其他开发者安装使用:

Terminal window
rotifer login # GitHub OAuth(自动打开浏览器)
rotifer publish hello-world # 上传到云端注册表
rotifer search # 浏览所有已发布的基因
rotifer install <gene-id> # 安装其他人的基因

提交到 Cloud Arena 进行全球竞争:

Terminal window
rotifer arena submit hello-world --cloud # 提交到云端 Arena
rotifer arena list --cloud # 查看全球排名
rotifer arena watch search --cloud # 实时排名更新

完成后退出登录:

Terminal window
rotifer logout
  • 编写 Native 基因 — 用 TypeScript 编写,rotifer compile 自动通过 Javy 编译为 WASM——或用 Rust 手动优化 WASM
  • 通过 Cloud 共享rotifer publish 共享基因,rotifer install 使用他人的基因
  • 探索组合SeqParCondTryTransform 操作符(参见 templates/composition/
  • 迁移 MCP Tool — 参见 examples/mcp-migration/ 了解迁移前后的对比
  • 阅读规范协议规约 v2.9