Capsule Development
它能做什么
这项技能指导构建胶囊,即在 Unicity AOS 中运行的小型安全程序。适合希望为智能体系统编写并安装新程序模块的开发者。
适用场景
- ✓当你想为 Unicity AOS 设置创建一个新胶囊的时候。
- ✓当胶囊构建、链接或安装失败,需要调试的时候。
- ✓当你需要检查胶囊的访问规则是否设置正确的时候。
技能链接
https://github.com/unicity-aos/aos-ce/blob/main/capsules/capsule-system/src/skills/capsule-development/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请使用受支持的模板创建一个新的 Unicity AOS 胶囊,构建它,并安装以便测试。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体从官方项目模板开始,设置控制胶囊可访问内容的清单文件。然后它为所需目标进行构建,并在安装之前检查访问列表。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Capsule Development
A capsule is a Rust WebAssembly component that runs inside the Astrid Runtime sandbox shipped by Unicity AOS. The runtime routes IPC, enforces capabilities, mediates host access, and audits execution. Business logic belongs in capsules.
The manifest is part of the security boundary. Its [publish] and [subscribe]
tables are the IPC access-control list: a topic that is not declared is denied.
Capsules target wasm32-unknown-unknown, not WASI, and reach the host only through
the audited SDK/WIT imports granted by the manifest.
Start from the supported scaffold
aos capsule new my-capsule
cd my-capsule
The generated project contains:
my-capsule/
├── .cargo/config.toml
├── rust-toolchain.toml
├── Cargo.toml
├── Capsule.toml
└── src/lib.rs
Do not begin from an old [[interceptor]] manifest or an ipc_publish /
ipc_subscribe capability array. Those formats are obsolete.
Compiler target
.cargo/config.toml selects the capsule target and activates the SDK's custom
randomness backend:
[build]
target = "wasm32-unknown-unknown"
[target.wasm32-unknown-unknown]
rustflags = ["--cfg=getrandom_backend=\"custom\""]
The getrandom_backend setting must live in the final capsule crate. Without it,
dependencies such as UUID generators or randomized hash maps can fail to link.
Pin the toolchain and target in rust-toolchain.toml:
[toolchain]
channel = "1.94.0"
targets = ["wasm32-unknown-unknown"]
components = ["rustfmt", "clippy"]
Cargo package
Use a cdylib and the current 0.7 SDK surface:
[package]
name = "my-capsule"
version = "0.1.0"
edition = "2024"
publish = false
[lib]
crate-type = ["cdylib"]
[dependencies]
astrid-sdk = { version = "0.7", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = "abort"
Capsule manifest
This minimal tool capsule exposes one hello tool:
[package]
name = "my-capsule"
version = "0.1.0"
description = "A small example capsule"
authors = ["Your Name <you@example.com>"]
astrid-version = ">=0.7.0"
[[component]]
id = "my-capsule"
file = "my_capsule.wasm"
type = "executable"
[capabilities]
fs_read = ["home://data/my-capsule/"]
fs_write = ["home://data/my-capsule/"]
[publish]
"tool.v1.execute.*.result" = { wit = "@unicity-astrid/wit/types/tool-call-result" }
"tool.v1.response.describe.*" = { wit = "@unicity-astrid/wit/tool/describe-response" }
[subscribe]
"tool.v1.execute.hello" = { wit = "@unicity-astrid/wit/types/tool-call", handler = "tool_execute_hello" }
"tool.v1.request.describe" = { wit = "@unicity-astrid/wit/tool/describe-request", handler = "tool_describe" }
Skills are agent user-space instructions, not a Capsule.toml protocol. Ship a trigger Skill through the host plugin or the agent-level Skills service, and expose capsule-owned reference material through typed IPC tools when useful. Do not add an agent Skill section to the manifest or request filesystem write authority merely to modify a host's instruction directory.
The published @unicity-astrid/wit/... strings and astrid:* WIT namespaces
are stable runtime identifiers. Keep them exact even though the product CLI is
aos.
For a tool capsule, both publish entries are required: one returns tool results,
and the other answers the describe fan-out that makes tools visible to agents.
Every tool needs its own concrete execute subscription. A subscribe wildcard may
have one trailing *; publish permissions should be as narrow as practical.
Manifest data is untrusted input. Do not put operator authority, principal identity, or a secret scope in a capsule-controlled field. The kernel stamps the caller identity and decides operator-only policy.
Implement a tool
#![deny(unsafe_code)]
#![deny(clippy::all)]
use astrid_sdk::prelude::*;
use astrid_sdk::schemars;
use serde::Deserialize;
#[derive(Default)]
pub struct MyCapsule;
#[derive(Debug, Default, Deserialize, schemars::JsonSchema)]
pub struct HelloArgs {
/// Person to greet.
pub name: String,
}
#[capsule]
impl MyCapsule {
/// Greet a person by name.
#[astrid::tool("hello")]
pub fn hello(&self, args: HelloArgs) -> Result<String, SysError> {
Ok(format!("Hello, {}!", args.name))
}
}
The tool macro derives the input schema from JsonSchema, uses the method's doc
comment as the tool desc
常见问题
清单文件为什么重要?
它的访问列表控制胶囊可以发送和接收哪些消息,凡是未声明的内容都会被拒绝。
我可以从旧示例开始吗?
不可以。旧的清单格式已经废弃,因此这项技能从当前模板开始。
我需要懂 Rust 吗?
这项技能使用 Rust,因此懂 Rust 的开发者会获益最多。
详情
作者的原始描述
Build, test, package, install, and debug a current Unicity AOS capsule
repo: unicity-aos/aos-ce
热度
- GitHub 星标
- 8.5k
- 排名
- #12454
- 许可证
- Apache-2.0
- 更新时间
- 2026/10/22
评论
- …