闲社服务运行正常AI智能体自动化平台
t

任务保护

技能标识:task-protection

Comprehensive task lifecycle management with automatic tracking, failure analysis, and completion feedback. Use when executing recurring system tasks (backups, health checks, news delivery), critical operations (config changes, data sync, deployments), external interactions (email sending, message notifications, API calls), user-delegated one-time tasks, or long-running operations over 1 minute. Provides 9 tool functions, 8 failure type analysis, progress tracking, and automated reporting.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

任务保护

Task Protection - 任务闭环管理机制

核心原则:所有重要任务必须有记忆、追踪、反馈、故障分析机制 —— 闭环管理


🚀 快速开始

基础用法(脚本中)

bash
#!/bin/bash
source /path/to/task-utils.sh

1. 初始化任务

TASKID=mytask$(date +%Y%m%d%H%M%S) taskinit $TASKID 任务名称 任务描述

2. 开始执行

taskstart $TASKID

3. 记录过程

tasklog $TASKID INFO 正在执行...

4. 完成任务

taskcomplete $TASKID 执行成功

或失败时

taskfail $TASKID 错误信息 错误类型

AI 直接执行的任务

AI 在回复中说明并创建状态文件:

📋 任务登记:

  • - ID: task202603140948writearticle
  • 名称:撰写文章
  • 状态:执行中

✅ 任务完成!
📋 详情:
- 完成时间:09:48
- 耗时:45 秒
- 状态:成功

📄 状态文件:memory/tasks/task202603140948writearticle.json



📁 文件结构

task-protection/
├── SKILL.md (本文件)
├── scripts/
│ ├── task-utils.sh # 核心工具函数库(9 个函数)
│ ├── ai-task-register.sh # AI 任务自动登记
│ ├── daily-news.sh # 示例:新闻推送
│ ├── system-health-check.sh # 示例:健康检查
│ ├── check-tasks.sh # 示例:任务扫描
│ └── weekly-task-report.sh # 周报统计
├── memory/
│ ├── task-registry.json # 任务注册表
│ └── tasks/ # 任务状态文件目录
├── logs/
│ └── tasks/ # 任务日志目录
└── docs/
├── QUICKSTART.md # 快速上手指南
├── task-trigger-criteria.md # 触发标准
└── ai-task-registration.md # AI 登记指南



🎯 何时使用

✅ 需要完整闭环的任务(5 类)

  1. 1. 周期性任务 —— 新闻推送、健康检查、备份、定时同步
  2. 关键操作 —— 配置修改、数据同步、系统升级、服务重启
  3. 对外交互 —— 邮件发送、消息推送、API 调用、文件上传
  4. 用户委托 —— 用户直接交代的任务(写文章、分析文件等)
  5. 长时间运行 —— 执行时间 > 1 分钟的任务

⚠️ 可简化处理的任务(3 类)

  • - 简单查询 —— 只读操作,无副作用(读取文件、查看状态)
  • 即时对话 —— 纯聊天、问答
  • 探索性工作 —— 研究性、尝试性任务

🛠️ 核心工具函数(9 个)

1. task_init - 初始化任务

bash
taskinit task001 发送邮件 向团队发送周报

参数:

  • - taskid - 任务 ID(建议格式:类型YYYYMMDDHHMMSS描述)
  • taskname - 任务名称
  • taskdescription - 任务描述(可选)

输出:

  • - 创建状态文件 memory/tasks/{task_id}.json
  • 记录初始化日志



2. task_start - 开始执行

bash
taskstart task001

功能:

  • - 更新状态为 running
  • 记录开始时间
  • 添加执行阶段



3. task_log - 记录日志

bash
tasklog task001 INFO 邮件发送中...
tasklog task001 WARN 网络延迟
tasklog task001 ERROR 发送失败

日志级别:

  • - INFO - 正常进度
  • WARN - 可恢复问题
  • ERROR - 失败/异常
  • DEBUG - 调试信息



4. task_stage - 更新阶段

bash
taskstage task001 准备内容 running
taskstage task001 准备内容 done
taskstage task001 验证结果 warning

阶段状态:

  • - running - 进行中
  • done - 完成
  • failed - 失败
  • warning - 警告



5. task_complete - 完成任务

bash
taskcomplete task001 邮件已发送,收件人:team@company.com

功能:

  • - 更新状态为 success
  • 记录完成时间和耗时
  • 保存结果信息



6. task_fail - 失败处理

bash
taskfail task001 发送超时 timeout

故障类型(8 类):

  • - commandnotfound - 命令不存在
  • authenticationfailed - 认证失败
  • networkerror - 网络错误
  • timeout - 执行超时
  • resourcenotfound - 资源不存在
  • permissiondenied - 权限不足
  • validationerror - 验证失败
  • unknown_error - 未知错误

功能:

  • - 更新状态为 failed
  • 自动分析故障原因
  • 提供修复建议
  • 记录错误详情



7. task_retry - 重试任务

bash
taskretry task001 3 60 # 最多 3 次,间隔 60 秒

参数:

  • - taskid - 任务 ID
  • maxretries - 最大重试次数(默认 3)
  • interval - 重试间隔秒数(默认 60)

退避策略:

  • - linear - 线性退避(60s, 60s, 60s)
  • exponential - 指数退避(30s, 60s, 120s)
  • fixed - 固定间隔



8. task_status - 查询状态

bash
taskstatus task001

输出:JSON 格式的任务状态



9. task_list - 列出任务

bash
task_list

输出:所有已登记任务列表



📊 任务状态文件结构

json
{
taskId: task202603140948_example,
name: 任务名称,
description: 任务描述,
status: success|failed|running|pending,
stages: [
{name: 准备, status: done, timestamp: ...},
{name: 执行, status: done, timestamp: ...}
],
logs: [[2026-03-14 09:48:00] [INFO] 任务初始化],
errors: [],
result: 任务完成,
duration: 120,
createdAt: 2026-03-14T09:48:00+08:00,
startedAt: 2026-03-14T09:48:00+08:00,
completedAt: 2026-03-14T09:50:00+08:00
}



🔄 典型工作流

脚本任务示例

bash
#!/bin/bash
source /path/to/task-utils.sh

TASKID=healthcheck$(date +%Y%m%d%H%M%S)

初始化

taskinit $TASKID 系统健康检查 检查 Gateway、磁盘、内存、日志 taskstart $TASKID

阶段 1: 检查 Gateway

taskstage $TASKID 检查 Gateway running if systemctl --user is-active openclaw-gateway > /dev/null 2>&1; then tasklog $TASKID INFO ✅ Gateway 运行正常 taskstage $TASKID 检查 Gateway done else tasklog $TASKID ERROR ❌ Gateway 未运行 taskstage $TASKID 检查 Gateway failed fi

阶段 2: 检查磁盘

taskstage $TASKID 检查磁盘 running

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 task-protection-1776074117 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 task-protection-1776074117 技能

通过命令行安装

skillhub install task-protection-1776074117

下载

⬇ 下载 task-protection v1.0.0(免费)

文件大小: 26.81 KB | 发布时间: 2026-4-15 14:36

v1.0.0 最新 2026-4-15 14:36
Initial release of task-protection 1.0.0

- Introduces a comprehensive task lifecycle management system with automatic tracking, failure analysis, and completion feedback.
- Provides 9 core tool functions for task registration, logging, stage tracking, status queries, and automated reporting.
- Supports 8 types of failure analysis, customizable retry logic, and progress tracking.
- Includes script examples and AI-friendly registration methods for recurring, critical, or long-running tasks.
- Features structured logging, JSON-based status files, summary reports, and detailed documentation for best practices and troubleshooting.
返回顶部