内容
# 统一性 Astrid 操作系统
<p align="center">
<img src="assets/astrid-github-preview.png" alt="统一性 Astrid 操作系统" width="640">
</p>
**一个用于 AI 代理的模块化操作系统。从密封部分构建,任意部分可替换,保持每项功能可控。**
[](https://github.com/unicity-astrid/astrid/actions/workflows/ci.yml)
[](https://github.com/unicity-astrid/astrid/actions/workflows/codeql.yml)
[](#license)
[](https://www.rust-lang.org)
[](https://www.rust-lang.org)
[](https://github.com/unicity-astrid/book)
---
统一性 Astrid 操作系统将 AI 代理视为操作系统对待进程的方式。每个能力都是一个密封的 WebAssembly **胶囊**:模型、循环、内存、工具、技能、守卫和前端。将它们组合成一个代理,稍后可以替换任何部分,而代理永远不会超出您给予它的权限。统一性 Astrid 操作系统可以在您已经使用的代理下面运行。
其底层的内核很小且故意很简单。它路由事件、强制执行权限、运行沙盒并记录审计跟踪;它不持有任何模型、工具模式或业务逻辑。越狱、毒化工具或普通错误仍然无法读取文件、访问网络或在其授权之外生成进程。权限是内核强制执行的权限,不是模型被信任遵循的指令。
## 快速开始
```bash
brew tap unicity-astrid/tap && brew install astrid
astrid init # 选择提供商,输入其密钥,安装发行版
astrid doctor # 验证守护进程、胶囊和 LLM 是否准备就绪
astrid chat # 启动会话;守护进程自动启动
```
从 [Astrid 网站](https://unicity-astrid.github.io/) 开始进行现场参观,从 [The Astrid Book](https://unicity-astrid.github.io/book/) 开始了解架构,或参阅 [Contributor Handbook](https://unicity-astrid.github.io/handbook/) 为统一性 Astrid 操作系统做出贡献。
## 为什么存在统一性 Astrid 操作系统
代理框架信任提示。统一性 Astrid 操作系统信任运行时。代理是在您的机器上运行的不可信代码,可以访问您的文件、网络和凭证。告诉它表现良好不是一个安全边界。操作系统级别的边界才是。
- **加密能力模型。** 每个文件路径、网络主机和工具都是带有 ed25519 签名的授权,限定资源模式、主体绑定、到期检查和全局可撤销。没有授权就没有访问权限。
- **没有环境权限的 WASM 沙盒。** 胶囊在 Wasmtime 中运行,没有系统调用、文件描述符和主机内存。每个外部效果都是能力检查的主机调用,跨 WIT 类型的 ABI。
- **内核很简单。** 它实例化一个事件总线,加载胶囊,并在能力 ACL 下路由 IPC 字节。它没有 LLM 句柄,没有会话状态,也没有工具注册表。所有智能都存在于胶囊中,因此胶囊错误不会破坏共享内核状态。
- **每个主体都有自己的权限。** 每个身份都获得隔离的胶囊访问、KV 数据、秘密、主目录、配额和审计链。一个主体永远无法读取另一个主体的命名空间,如果调用者无法解析,则失败并关闭。
- **签名、哈希链接审计链。** 每个条目都密封前一个条目的哈希并签名。破坏链条,篡改就会被发现。
- **实时胶囊生命周期。** 在运行的守护进程上安装、升级和删除胶囊。无需重启。
## 它是如何工作的
前端(CLI、HTTP 网关、Discord 等)是 **上行链路**:连接到守护进程的协议客户端,通过 Unix 域套接字进行 IPC 事件通信。没有 `Frontend` 特性。上行链路发布事件并像其他总线参与者一样接收响应。
```mermaid
flowchart TB
CLI[CLI] -->|IPC events over Unix socket| Kernel
HTTP[HTTP gateway] -->|IPC events| Kernel
Discord[Discord] -->|IPC events| Kernel
Uplinks[Other uplinks] -->|IPC events| Kernel
subgraph Runtime[统一性 Astrid 操作系统运行时]
Kernel[Kernel: astrid-daemon<br/>dumb event router<br/>event bus - capability ACL - audit chain - Wasmtime sandbox]
Capsules[WASM Component capsules: wasm32-unknown-unknown<br/>providers - orchestrators - tools - fs - http - sessions - registry - identity]
end
Kernel -->|capability-checked host calls<br/>astrid:* WIT ABI| Capsules
```
胶囊通过总线进行通信。每个胶囊在 `Capsule.toml` 清单中声明其需求和提供的内容,带有类型化的 `[imports]`/`[exports]` 表;内核通过拓扑排序解析依赖图,并按顺序启动胶囊。工具是一种 IPC 约定,而不是内核概念:工具胶囊拦截 `tool.v1.execute.<name>`,内核从未看到工具模式。
主机 ABI 是 WebAssembly 组件模型,带有版本化的 `astrid:*` WIT 包:`fs`、`io`、`kv`、`ipc`、`net`、`http`、`sys`、`process`、`approval`、`identity`、`elicit` 和 `uplink`。客人仅导入其清单允许的内容,每个调用都在边界处按能力进行检查。
## 安全模型
Astrid 的安全性是分解的。没有单个网关可以控制所有操作。胶囊没有环境权限,授权由独立的、按区域划分的机制强制执行,每个机制都关闭失败,并且在实际发生时强制执行。
```mermaid
flowchart TB
Action[A capsule action] --> Sandbox[WASM sandbox<br/>no syscalls, file descriptors, or host memory<br/>external resources are capability-checked host calls]
Action --> Manifest[Manifest gate<br/>declared file, network, and process allow-list<br/>empty is deny-all; path traversal and SSRF defenses]
Action --> IPC[IPC ACL<br/>declared publish and subscribe topics only<br/>per-principal routing]
Action --> Capability[Capability token<br/>ed25519, principal-bound, scoped, expiring, revocable<br/>per-device tokens can be subset-scoped]
Action --> Approval[Approval gate<br/>once - session - always - deny<br/>allow always mints a token; local egress elicits consent]
Action --> OS[OS sandbox<br/>bwrap on Linux - seatbelt on macOS for native subprocesses]
Action --> Audit[Audit chain<br/>signed, hash-linked JSONL decisions and calls<br/>split per principal and independently verifiable]
```
这些机制是真实且独立测试的。没有统一的拦截器来协调它们。[The Astrid Book](https://github.com/unicity-astrid/book) 中的 [five-layer gate](https://github.com/unicity-astrid/book) 章节针对源代码逐一介绍了每个层。
## 安装
**Homebrew(macOS 和 Linux):**
```bash
brew tap unicity-astrid/tap
brew install astrid
```
**从 crates.io(需要 Rust 1.95+):**
```bash
cargo install astrid
```
**从源代码:**
```bash
git clone https://github.com/unicity-astrid/astrid
cd astrid && cargo build --release # binary at ./target/release/astrid
```
Astrid 安装四个二进制文件,它们一起工作。您只需要调用 `astrid`;它启动并管理其余部分。
| 二进制文件 | 角色 |
|---|---|
| `astrid` | CLI 上行链路。通过 Unix 套接字连接到守护进程。TUI、头less 模式、胶囊和代理管理。 |
| `astrid-daemon` | 内核进程。加载胶囊、路由 IPC、强制执行权限、运行沙盒。 |
| `astrid-build` | 胶囊编译器和打包器。构建到 `wasm32-unknown-unknown`。 |
| `astrid-emit` | Stdio-to-bus 桥,用于外部钩子生产者。 |
## 初始设置
`astrid init` 获取一个 *distro*(一个精选的胶囊包),呈现提供商的多选,提示每个提供商所需的凭据,包括其 API 密钥。秘密存储在每个主体的秘密存储中,从不通过命令行传递。`init` 编写一个 `Distro.lock`,锁定每个胶囊的 BLAKE3 哈希,以便相同的 `init` 复制相同的舰队。
```bash
astrid init # interactive: pick provider(s), enter keys
astrid init --yes # non-interactive, accept defaults
astrid init --offline ./bundle.shuttle # install a signed bundle, no network
astrid init --distro @yourorg/your-distro
```
在启动过程中,模型字段从提供商的 `/v1/models` 端点发现提供商的实时模型列表。初始化后,确认代理循环就绪,然后与其对话:
```bash
astrid doctor # daemon up? capsules ready? an LLM available?
astrid chat # interactive session; the daemon auto-starts on first use
astrid models # list the current provider's models (a registry-capsule verb)
```
### 无头和脚本
```bash
astrid -p "summarize the git log" # single prompt, prints and exits
git diff HEAD~1 | astrid -p "write a commit message" # stdin is appended to the prompt
astrid -p "fix all failing tests" --yes # auto-approve tool requests
astrid -p "continue" --session "$SID" # resume by id or name
```
### 守护进程生命周期
```bash
astrid start # persistent daemon (survives terminal close)
astrid status # PID, uptime, connected clients, loaded capsules
astrid ps # loaded capsules and their lifecycle state
astrid stop # graceful shutdown
astrid update # download, verify, and stage the latest release (self-update alias)
```
## 每个主体的隔离
每个主体(代理身份)都是一个完全隔离的租户:它自己的胶囊访问、KV 命名空间、秘密、主目录、配额和审计链。新主体默认情况下不会继承任何内容。
```bash
astrid agent create ci-bot # clean-slate, least-privilege agent
astrid agent create staging --clone production # full profile + state replica
astrid agent modify ci-bot \
--add-capsule astrid-capsule-fs # grant access to a capsule's tools
astrid caps show ci-bot # inspect capability grants
astrid quota set -a ci-bot --memory 128MB # per-principal resource limits
astrid pair-device issue --scope use-only # scope a device token to a subset
```
胶囊访问在调度时在内核端强制执行。主体只能调用明确授予它的胶囊,并且安装相同胶囊字节的两个主体共享一个内容寻址的磁盘上工件,同时获得单独的内存运行时实例。
## 编写胶囊
胶囊是一个用清单描述的 WASM 进程。脚手架生成一个第一尝试编译的项目,针对 `wasm32-unknown-unknown`,以及一个 `AUTHORING.md` 指南。
```bash
astrid capsule new my-capsule # scaffold Capsule.toml, Cargo.toml, src/lib.rs, .cargo/config.toml
cd my-capsule
astrid capsule build # compile and package
astrid capsule install . # hot-loaded into the running daemon, no restart
```
胶囊作者依赖于 [`astrid-sdk`](https://github.com/unicity-astrid/sdk-rust),它镜像了 `std` 模块布局(`fs`、`net`、`process`、`env`、`time`、`log`)并添加了 Astrid 模块(`ipc`、`kv`、`http`、`hooks`、`uplink`、`identity`、`approval`)。`#[capsule]` 过程宏生成 WASM ABI 样板:导出、序列化以及工具、命令、钩子和生命周期入口点的调度。
```rust
use astrid_sdk::prelude::*;
#[derive(Default)]
struct Weather;
#[capsule]
impl Weather {
#[astrid::tool]
fn forecast(&self, args: ForecastArgs) -> Result<Forecast, SysError> {
let key = env::var("WEATHER_API_KEY")?;
let body = http::get(&format!("https://api.example.com/wx?q={}", args.city))?;
Ok(serde_json::from_slice(&body)?)
}
}
```
构建胶囊是 Astrid 中的一流工作流。Forge(`astrid capsule new` 加上创作工具和脚手架技能)是登机台;方向是一个编写、构建和安装自己的胶囊的主体,在能力沙盒内。
### 实时胶囊生命周期
```bash
astrid capsule install @org/capsule-name # install and hot-load
astrid capsule update my-capsule # hot-swap the running instance
astrid capsule remove my-capsule # live-unload, no restart
astrid capsule list --verbose # installed capsules with capability metadata
astrid capsule tree # imports/exports dependency graph
```
## 0.9 中的新增功能
五项工作成果以及安全强化通道。查看 [CHANGELOG.md](CHANGELOG.md) 以获取完整列表。
- **实时胶囊生命周期。** 安装时热加载,升级时热交换,移除时实时卸载,都无需重启守护进程。
- **每个主体的隔离,强化端到端。** 主体视图感知胶囊加载,内容寻址工件重用,内核级工具表面访问强制执行,以及 HTTP 网关的设备令牌范围。
- **LLM 提供商和模型绑定。** 多提供商注册,实时模型发现,以及网关路由和 `astrid models` / `astrid doctor` 用于每个主体的模型管理和循环就绪检查。
- **HTTP 网关上的对话线程。** 线程列表、获取、更新、删除和全文搜索,以及每个主体的实时对话提要,并在总线上强制执行跨主体隔离。
- **`astrid:http@1.1.0` 和操作员可配置的限制。** 每个请求的超时、重定向策略、正文上限、`https-only` 和子资源完整性;七个以前硬编码的天花板成为操作员旋钮。
- **安全。** 本地出口同意(传输源标记、运行时诱导、每个胶囊和每个主体的授权)、一个关闭 IP 字面和重定向绕过的 SSRF 防空隔离,以及强化供应链路径(Sigstore 证明、CodeQL、固定操作 SHA、最少权限令牌)。
## 文档
- **[The Astrid Book](https://github.com/unicity-astrid/book)** 是规范参考:内核、胶囊模型、主机 ABI、总线和安全模型,基于源代码,带有文件和行锚。从 [Getting Started](https://github.com/unicity-astrid/book) 开始,几分钟内从零开始构建一个工作代理。
- **操作员指南** 位于 [`docs/`](docs/):统一配置模式、 [LLM 模型选择](docs/models.md)、[distro signing](docs/distro-signing.md)、[gateway deployment runbook](docs/gateway-deployment.md) 和 [generating a gateway client](docs/gateway-client.md)。
## 开发
```bash
cargo build --workspace
cargo test --workspace -- --quiet
cargo clippy --workspace --all-features -- -D warnings
cargo fmt --all -- --check
```
所有 crate 都强制执行 `#![deny(unsafe_code)]`,除了 `astrid-sys` 和 `astrid-sdk`,其中 WASM FFI 需要它。Clippy 以严格级别运行,整数溢出算术是 lint 错误。macOS 和 Linux(x86_64 和 aarch64)的发布二进制文件在标签推送时构建,并使用无密钥 Sigstore 证明。
## 贡献
欢迎贡献。Astrid 使用分层贡献者系统,保护安全关键代码,同时为新贡献者敞开大门。每个拉取请求必须链接到 GitHub 问题。有关问题优先的工作流和层描述,请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。
对任何合同表面(主机 ABI、IPC 协议、能力模型、清单模式或 SDK 公共 API)的更改都经过 RFC 流程,在 [RFCs repository](https://github.com/unicity-astrid/rfcs) 中实施前。
## 许可证
双重许可在 [MIT](LICENSE-MIT) 和 [Apache 2.0](LICENSE-APACHE) 下,任您选择。
版权 (c) 2025-2026 Joshua J. Bouw 和 Unicity Labs。
连接信息
猜你喜欢
暂无推荐服务器