task-automation
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "task-automation" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-a09ca8a028ac58efec501ec7db955b40c18af4560fb6aa2c17b35b905e9b148b. Verify the upstream source and version against https://skillhub.cn/skills/user_3c6cb52e/task-automation before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Automate repetitive tasks and workflows using scripts, file listeners, scheduled jobs, CI triggers, and API polling to eliminate manual interventions.
Introduction source: third_party · user_3c6cb52e · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: task-automation
description: 使用脚本、文件监听器、计划任务、CI 触发器和 API 轮询来自动化重复性任务和工作流,以消除手动操作。Task Automation
此技能使 AI agent 能够为重复性任务和工作流设计并实现自动化。agent 识别适合自动化的手动流程,选择合适的自动化模式(脚本、文件监听器、cron 任务、CI/CD 触发器、API 轮询),编写实现代码,并验证其正确运行。目标是消除“toil”——即随着工作量线性增长的重复性、手动操作,并用可靠、无需干预的自动化替代它。
Workflow
-
分析任务: 理解用户想要自动化的任务,包括触发条件(什么启动该任务)、涉及步骤、输入输出以及当前手动执行频率。判断任务是事件驱动型(由变化触发)还是时间驱动型(按计划运行)。
-
选择自动化模式: 根据触发类型和环境选择合适的自动化方法。常见模式包括:shell 脚本用于一次性或顺序任务,文件监听器(fswatch、inotifywait、chokidar)用于响应文件变化,cron 任务或 systemd 定时器用于计划重复任务,CI/CD 流水线触发器用于代码相关自动化,API 轮询或 webhook 监听器用于响应外部服务事件。
-
设计实现方案: 详细规划自动化流程:定义输入和配置、错误处理策略(重试逻辑、告警机制、回退行为)、日志记录方式以及所需的密钥或凭证管理。考虑幂等性——自动化应能多次运行而无副作用。
-
编写自动化代码: 使用适当的工具和语言实现自动化。优先使用成熟且广泛支持的工具:bash/Python 用于脚本,crontab 用于调度,GitHub Actions 或 GitLab CI 用于 CI 触发器,标准 webhook 框架用于事件监听器。
-
测试与验证: 首先在安全环境中运行自动化。验证其正确处理正常路径后,再测试边界情况:空输入、网络故障、权限错误和并发执行。确认日志记录足够信息以便调试。
-
部署与监控: 在目标环境中部署自动化,并设置适当的权限。建立监控或告警机制,以便及时发现失败。记录自动化的目的、配置及如何禁用它的方法。
Usage
描述你想要自动化的任务,包括触发条件、应执行的操作以及运行位置。agent 将选择合适的模式并实现它。
Automate the following: whenever a new CSV file is added to the ~/data/incoming/
directory, validate the CSV headers, transform the data into JSON, and move the
result to ~/data/processed/. Log any files that fail validation to ~/data/errors/.
Examples
示例 1:带处理管道的文件监听器
用户请求:
Automate processing of incoming CSV files in a directory.
实现方式:
#!/usr/bin/env python3
"""File watcher that processes incoming CSVs into JSON.
Usage: python csv_watcher.py
Watches: ~/data/incoming/ for new .csv files
Outputs: ~/data/processed/*.json and ~/data/errors/error.log
"""
import os
import csv
import json
import time
import logging
from pathlib import Path
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
INCOMING = Path.home() / "data" / "incoming"
PROCESSED = Path.home() / "data" / "processed"
ERRORS = Path.home() / "data" / "errors"
REQUIRED_HEADERS = ["id", "name", "email", "amount"]
logging.basicConfig(
filename=ERRORS / "error.log",
level=logging.ERROR,
format="%(asctime)s - %(message)s"
)
for d in [INCOMING, PROCESSED, ERRORS]:
d.mkdir(parents=True, exist_ok=True)
class CSVHandler(FileSystemEventHandler):
def on_created(self, event):
if not event.src_path.endswith(".csv"):
return
filepath = Path(event.src_path)
try:
with open(filepath, "r") as f:
reader = csv.DictReader(f)
headers = reader.fieldnames or []
missing = set(REQUIRED_HEADERS) - set(headers)
if missing:
raise ValueError(f"Missing headers: {missing}")
rows = list(reader)
output = PROCESSED / filepath.with_suffix(".json").name
with open(output, "w") as f:
json.dump(rows, f, indent=2)
filepath.unlink() # Remove processed file
print(f"Processed: {filepath.name} -> {output.name}")
except Exception as e:
logging.error(f"Failed to process {filepath.name}: {e}")
filepath.rename(ERRORS / filepath.name)
if __name__ == "__main__":
observer = Observer()
observer.schedule(CSVHandler(), str(INCOMING), recursive=False)
observer.start()
print(f"Watching {INCOMING} for new CSV files...")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
示例 2:基于 Cron 的 API 轮询与 Slack 通知
用户请求:
Every 6 hours, check our API health endpoint and post to Slack if any service is degraded.
实现方式:
Cron 条目(通过 crontab -e 添加):
0 */6 * * * /usr/bin/python3 /opt/scripts/health_check.py >> /var/log/health_check.log 2>&1
Script:
#!/usr/bin/env python3
"""Poll API health endpoint and alert Slack on degraded services.
Runs every 6 hours via cron. Exits 0 on success, 1 on alert sent, 2 on script error.
"""
import os
import json
import urllib.request
HEALTH_URL = "https://api.example.com/health"
SLACK_WEBHOOK = os.environ["SLACK_WEBHOOK_URL"]
def check_health():
req = urllib.request.Request(HEALTH_URL, headers={"Accept": "application/json"})
with urllib.request.urlopen(req, timeout=10) as resp:
data = json.loads(resp.read())
return data # e.g., {"services": {"auth": "ok", "payments": "degraded", "db": "ok"}}
def send_slack_alert(degraded_services):
service_list = "\n".join(f"- *{name}*: {status}" for name, status in degraded_services)
payload = json.dumps({
"text": f":warning: *Service Health Alert*\n{service_list}"
}).encode()
req = urllib.request.Request(
SLACK_WEBHOOK,
data=payload,
headers={"Content-Type": "application/json"},
method="POST"
)
urllib.request.urlopen(req)
if __name__ == "__main__":
health = check_health()
degraded = [
(name, status)
for name, status in health.get("services", {}).items()
if status != "ok"
]
if degraded:
send_slack_alert(degraded)
print(f"Alert sent for {len(degraded)} degraded service(s)")
exit(1)
else:
print("All services healthy")
exit(0)
最佳实践
- 使自动化具备幂等性。 使用相同输入运行相同的自动化两次应产生相同结果且无副作用。这可防止任务意外重新触发导致数据损坏。
- 记录所有内容,选择性告警。 编写详细的日志用于调试,但仅对可操作的失败发送告警。满是“一切正常”通知的邮箱会让人忽略真正重要的告警。
- 外部化配置。 将文件路径、URL、阈值和凭证存储在环境变量或配置文件中,而不是硬编码在脚本中。这使自动化具备可移植性并便于管理密钥。
- 为计划任务使用锁文件或互斥机制。 如果前一个运行尚未完成,cron 任务可能重叠。使用
flock或 PID 文件确保同一时间只有一个实例运行。 - 对自动化脚本进行版本控制。 将自动化视为生产代码——将其存储在 Git 中、审查变更并打标签发布。损坏的自动化比损坏的功能造成更大影响。
- 包含手动覆盖机制。 每个自动化都应有文档说明如何暂停、跳过或手动运行它。在事件中,自动操作可能干扰手动修复时,这一点至关重要。
Edge Cases
- 多步骤自动化中的部分失败: 如果第 3 步(共 5 步)失败,自动化不应静默跳过。应实现检查点机制,使自动化能从上一个成功步骤恢复,而不是重新开始。
- 并发文件写入问题: 文件监听器可能在部分写入的文件上触发。处理前添加短暂延迟或检查文件稳定性(N 秒内大小未变)。
- 凭证过期问题: API token 和 OAuth 凭证会过期。为长期运行的自动化加入令牌刷新逻辑,并在刷新失败时告警,而不是静默退出。
- Cron 的时区问题: Cron 默认使用系统时区。对于全球团队,请明确使用 UTC 或记录时区。注意夏令时变化可能导致任务执行两次或跳过。
- 轮询 API 的速率限制: 如果间隔太短或多个实例运行,API 轮询可能达到速率限制。实现指数退避并跟踪速率限制头信息。
- 空或格式错误的输入: 由外部数据(文件、webhook、API 响应)触发的自动化应在处理前验证输入模式。优雅失败并给出清晰错误信息,而不是生成损坏输出。
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 高价值/高频刚需,直接解决用户明确的核心任务痛点
- 显著提升日常高频场景的效率
- 提供多种自动化模式(脚本、文件监听器、计划任务、CI 触发器和 API 轮询)
Highlights
- 触发词精准完整,覆盖多种变体
- 边界清晰,用户能准确理解 Skill 的适用范围
Highlights
- Phase/步骤清晰,有出口条件
- 含端到端示例,frontmatter完整
- 单文件≤500行,结构规范
Highlights
- 工具来源明确,参数正确
- 覆盖主要异常,不可逆操作有确认机制
- 提供了详细的错误处理和日志记录策略
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Read local files
Limit access to selected files or the project directory. Avoid unrelated private records, secrets and configuration files.
Mentioned in main document · lines 81 -
Save or modify files
Confirm the output directory and whether existing files will be replaced. Back up important files and prefer a new output directory.
Mentioned in main document · lines 90 -
Accounts, secrets or authorization
Use a dedicated least-privilege account. Keep secrets out of public content and command logs; verify the receiving service and tenant.
Mentioned in main document · lines 15, 182, 191
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- api.example.com
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.