feat: 多语言任务、WebUI 增强与 Agent MCP 集成

重构 lib 为扁平模块并支持 Windows schtasks;新增 JS/Bash/PowerShell 模板、WebUI 调度编辑,以及 Cursor Skill 与 MCP 工具供 Agent 管理定时任务。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-24 21:45:25 +08:00
parent 6c2db2dfa3
commit c10cacd5c6
59 changed files with 3989 additions and 800 deletions

View File

@@ -2,37 +2,60 @@
## 新建定时任务
**必须**`_template/` 复制(`_template` 本身是可运行的 hello world 示例任务)。
**默认从 `_template/`Python复制**;也可选用其他语言模板:
| 模板目录 | 语言 | 入口 |
|---|---|---|
| `_template` | Python默认 | `run.py` |
| `_template-javascript` | JavaScript | `run.js` |
| `_template-bash` | Bash | `run.sh` |
| `_template-powershell` | PowerShell | `run.ps1` |
```bash
TASK_ID="<主机名>-<功能描述>"
CRON_ROOT="/shumengya/project/agent/sproutclaw-cron"
cp -a "$CRON_ROOT/_template" "$CRON_ROOT/$TASK_ID"
sed -i "s/_template/$TASK_ID/g" "$CRON_ROOT/$TASK_ID/schedule.cron"
chmod +x "$CRON_ROOT/$TASK_ID/switch.sh"
TEMPLATE="_template" # 或 _template-javascript / _template-bash / _template-powershell
cp -a "$CRON_ROOT/$TEMPLATE" "$CRON_ROOT/$TASK_ID"
sed -i "s/$TEMPLATE/$TASK_ID/g" "$CRON_ROOT/$TASK_ID/schedule.cron"
# Bash 模板额外chmod +x "$CRON_ROOT/$TASK_ID/run.sh"
```
然后:
1. 修改 `run.py`保留 `task_is_disabled` / `task_logging` / `acquire_cron_lock` 结构,替换 `hello world` 为实际逻辑
2. 修改 `schedule.cron`:调整 cron 表达式与注释说明
3. 可选:添加任务专属 JSON 配置(如 `targets.json`
4. `python3 cronctl.py run <task-id>` 试跑,确认日志正常
5. 默认保持关闭;用户要求启用时再 `cronctl enable <task-id>`
1. **Python**修改 `run.py`保留 `task_is_disabled` / `task_logging` / `acquire_cron_lock` 结构
2. **其他语言**:只改入口脚本(`run.js` / `run.sh` / `run.ps1`disable / 锁 / 日志由 `cronctl run` 统一处理
3. 修改 `schedule.cron`:调整 cron 表达式与注释说明
4. 可选:任务专属 JSON 配置(如 `targets.json`
5. `python3 cronctl.py run <task-id>` 试跑,确认日志正常
6. 默认保持关闭;用户要求启用时再 `cronctl enable <task-id>`
## task.json
可选清单,声明运行时与入口(无则按入口文件自动推断):
```json
{
"runtime": "python",
"entry": "run.py"
}
```
`runtime` 取值:`python` | `javascript` | `bash` | `powershell`
## 不要修改
- `_template/` 是 hello world 示例任务,也是新任务复制源;除非用户要求,不要改其示例行为
- `_template*` 是 hello world 示例任务,也是新任务复制源;除非用户要求,不要改其示例行为
- 不要删除或移动已有任务的 `schedule.cron` 里对 `cronctl.py run` 的调用方式
## 任务目录约定
```
<task-id>/
├── run.py
├── task.json # 可选runtime + entry
├── run.py|run.js|run.sh|run.ps1
├── schedule.cron
├── switch.sh # 可选
├── logs/<task-id>.log # 运行时自动创建
├── logs/<task-id>.log
└── *.json # 可选配置
```
@@ -46,4 +69,10 @@ python3 /shumengya/project/agent/sproutclaw-cron/cronctl.py run <task-id>
python3 /shumengya/project/agent/sproutclaw-cron/cronctl.py enable <task-id>
```
WebUI`/shumengya/project/agent/sproutclaw-cron/webui/start.sh`
WebUI`/shumengya/project/agent/sproutclaw-cron/webui/start.sh` 或 Windows 下 `start-webui.bat`
## AI Agent 集成
- **Skill**`.cursor/skills/sproutclaw-cron/SKILL.md` — 操作规范与 workflow
- **MCP**`.cursor/mcp.json` 注册 `sproutclaw-cron` 服务器;工具前缀 `cron_*`
- MCP 依赖:`pip install -r mcp-server/requirements.txt`