介绍
# OpenClaw Async Task
## 描述
执行长时间运行的任务,避免 HTTP 超时。当你需要以下操作时使用: - 运行可能耗时超过 5 秒的命令 - 分析大文件或代码库 - 执行多步骤操作 - 调用具有不可预测延迟的外部 API
**重要提示**:当任务可能超时时,你**必须**使用此技能以避免 `empty response from server` 错误。
触发词:“async task”、“long running”、“timeout”、“background task”、“push result”
## 安装
```bash # Clone and link globally git clone https://github.com/Enderfga/openclaw-async-task.git cd openclaw-async-task npm link
# Or just copy async-task.js to your PATH chmod +x async-task.js cp async-task.js /usr/local/bin/async-task ```
## 命令
```bash async-task start "<description>" # Start task, returns immediately async-task done "<result>" # Complete task, push result to user async-task fail "<error>" # Task failed, push error message async-task push "<message>" # Push message directly (no start needed) async-task status # Show current task status ```
## 使用流程(必须严格遵循)
1. **开始**:`async-task start "正在扫描文件..."` 2. **执行**:运行你的实际命令 3. **推送结果**:`async-task done "找到 42 个文件"`
## 示例
用户问:“统计此项目中的所有 TypeScript 文件”
```bash # Step 1: Acknowledge immediately async-task start "Counting TypeScript files..."
# Step 2: Do the actual work count=$(find . -name "*.ts" | wc -l)
# Step 3: Push the result async-task done "Found $count TypeScript files" ```
## 工作原理
1. `start` 保存任务状态并立即返回确认 2. 你执行所需的任何命令 3. `done`/`fail` 使用 OpenClaw/Clawdbot CLI 将结果推送到活动会话
**无需配置** - 自动通过 `openclaw sessions` 或 `clawdbot sessions` 检测活动会话。
## 高级:自定义推送端点
用于自定义 Web 聊天或通知系统:
```bash export ASYNC_TASK_PUSH_URL="https://your-server.com/api/push" export ASYNC_TASK_AUTH_TOKEN="your-token" ```
该端点接收: ```json { "sessionId": "session-id", "content": "message", "role": "assistant" } ```
## 环境变量
| 变量 | 必填 | 描述 | |----------|----------|-------------| | `OPENCLAW_SESSION` | 否 | 目标会话(自动检测) | | `ASYNC_TASK_PUSH_URL` | 否 | 自定义 HTTP 推送端点 | | `ASYNC_TASK_AUTH_TOKEN` | 否 | 自定义端点的认证令牌 |
## 要求
- Node.js 16+ - 已安装 OpenClaw 或 Clawdbot CLI
## 关键规则
- **必须**将 `start` 与 `done` 或 `fail` 配对使用 - **切勿**开始后不完成 - **切勿**说“稍后推送”然后就忘了
## 链接
- [GitHub](https://github.com/Enderfga/openclaw-async-task) - [OpenClaw](https://openclaw.ai)