spaceship 是面向 AstrBot 的远程节点控制方案仓库。
agent/:Go 编写的跨平台节点客户端,负责连接 AstrBot 网关并执行远端任务
当前 AstrBot 侧的正式实现位于本体仓库中的 astrbot/core/spaceship/。
Spaceship 的目标是把 AstrBot 扩展成一个远端节点网关:
- 远端机器运行 Go agent 并与 AstrBot 建立 WebSocket 长连接
- AstrBot 作为控制面向在线节点派发任务
- LLM 可以通过工具查看节点、执行命令、列目录、读取文件、写入文件
- WebUI 可以管理 Spaceship 配置并查看节点状态
主实现已经落在 AstrBot core 子模块:
astrbot/core/spaceship/models.pyastrbot/core/spaceship/session.pyastrbot/core/spaceship/dispatcher.pyastrbot/core/spaceship/gateway.pyastrbot/core/spaceship/tools.pyastrbot/core/spaceship/tool_registry.pyastrbot/core/spaceship/components.pyastrbot/core/spaceship/runtime.py
配套接入点包括:
astrbot/core/core_lifecycle.pyastrbot/dashboard/routes/spaceship.pyastrbot/core/config/default.py- dashboard 前端页面、路由、侧边栏和 i18n
Go agent 当前负责:
- 读取
.env或环境变量配置 - 与 AstrBot 网关建立 WebSocket 连接
- 发送
node.hello - 接收
node.welcome - 定时发送
node.heartbeat - 接收
task.dispatch - 执行
exec、list_dir、read_file、write_file、edit_file、grep - 执行
delete_file、move_file、copy_file - 检测系统 Python 并自动创建/复用 venv,支持
exec_python - 回传
task.accepted、task.started、task.output、task.result - 在连接断开时自动退避重连
.
├─ README.md
├─ plans/
│ ├─ spaceship-astrbot-architecture.md
│ └─ spaceship-current-status.md
├─ agent/
│ ├─ .env
│ ├─ go.mod
│ ├─ go.sum
│ ├─ cmd/
│ │ └─ spaceship-agent/
│ │ └─ main.go
│ └─ internal/
│ ├─ config/
│ ├─ executor/
│ ├─ fileops/
│ ├─ heartbeat/
│ ├─ logger/
│ ├─ metadata/
│ ├─ policy/
│ ├─ protocol/
│ ├─ python/
│ ├─ registrar/
│ ├─ shell/
│ └─ wsclient/
└─ plugin/
└─ spaceship/
└─ ... (legacy prototype)
当前已经落地:
- AstrBot core 子模块化
spaceship - WebUI 配置页面、节点列表与节点详情接口
- WebSocket 网关接入路径
/api/spaceship/ws - LLM 工具注册:
listnode、getnodeinfo、executeshell、listdir、readfile、writefile - Go agent 的
.env配置加载 - Go agent 的基本日志输出
- Go agent 的自动重连与退避重试参数
- 最小联调闭环:hello / welcome / heartbeat / task.dispatch / task.result
当前已经接入 AstrBot 的 LLM 工具有:
listnode:查看当前在线或指定状态的节点列表getnodeinfo:查看指定节点的详细信息executeshell:在指定节点上执行 shell 命令listdir:查看指定节点上的目录内容readfile:读取指定节点上的文本文件内容writefile:向指定节点上的文件写入文本内容,支持覆盖或追加editfile:通过搜索替换编辑指定节点上的文件grepfile:在指定节点上搜索文件内容deletefile:删除指定节点上的文件或目录movefile:移动或重命名指定节点上的文件或目录copyfile:复制指定节点上的文件或目录executepython:在指定节点上执行 Python 代码(需节点安装 Python)
agent 支持三种配置方式,加载优先级为:
CLI flags > 环境变量 > YAML 配置文件 > 内置默认值
将 spaceship.yaml.example 复制为 spaceship.yaml:
server_url: ws://127.0.0.1:6185/api/spaceship/ws
node_id: dev-node-01
token: change-me
alias: Local Dev Node
log_level: info
heartbeat_interval: 20s
reconnect:
min_delay: 1s
max_delay: 30s
python:
path: "" # 留空则自动检测
skip_venv: falseagent 自动按以下顺序搜索配置文件:
--config命令行参数指定的路径SPACESHIP_CONFIG_FILE环境变量- 工作目录下的
spaceship.yaml/spaceship.yml - 可执行文件同目录下的
spaceship.yaml/spaceship.yml
spaceship-agent.exe --server ws://192.168.1.100:6185/api/spaceship/ws --node-id my-node --token secret可用 flags:
| Flag | 说明 |
|---|---|
--config |
指定 YAML 配置文件路径 |
--server |
AstrBot WebSocket 网关地址 |
--node-id |
节点唯一 ID |
--token |
认证 token |
--alias |
节点显示名称 |
--log-level |
日志级别 (debug/info/warn/error) |
agent 目录下的 .env 文件仍然支持(向后兼容):
SPACESHIP_SERVER_URL=ws://127.0.0.1:6185/api/spaceship/ws
SPACESHIP_NODE_ID=dev-node-01
SPACESHIP_NODE_ALIAS=Local Dev Node
SPACESHIP_NODE_TOKEN=change-me
SPACESHIP_LOG_LEVEL=info
SPACESHIP_HEARTBEAT_INTERVAL=20s
SPACESHIP_RECONNECT_MIN_DELAY=1s
SPACESHIP_RECONNECT_MAX_DELAY=30s
# Python 配置(可选)
# SPACESHIP_PYTHON_PATH=
# SPACESHIP_SKIP_PYTHON_VENV=falseSet-Location .\agent
go run .\cmd\spaceship-agentSet-Location .\agent
go build -trimpath -ldflags="-s -w" -o spaceship-agent.exe .\cmd\spaceship-agent
.\spaceship-agent.exeSet-Location .\agent
$env:GOOS="linux"
$env:GOARCH="amd64"
$env:CGO_ENABLED="0"
go build -trimpath -ldflags="-s -w" -o spaceship-agent .\cmd\spaceship-agent当前项目已经进入联调清障阶段,而不是纯方案阶段。
已经稳定完成的部分:
- 配置持久化
- dashboard 路由接入
- core 工具注册
- WebSocket 上下文问题修复
- 基础节点能力和远端文件/命令调用链路
仍在继续完善的部分:
task.cancel- 更细粒度权限控制
- 输出分块优化
- 审计落库
- 更完整的连接恢复与任务恢复策略