Skip to main content

AI-native 通用自动化流水线框架,内置 Claude Code runner

Project description

Harness

AI-native 通用自动化流水线框架,内置 Claude Code runner

PyPI Python License

核心理念

声明你的流水线,框架负责可靠执行、记录、重试、调度、通知。

  • Claude Code runner 优先:调用 Claude Code CLI 子进程,完整工具链 + bypassPermissions + session 持久化
  • Task 类型多态:LLMTask / FunctionTask / ShellTask / PollingTask / Parallel,混合编排
  • 开箱即用:SQLite 存储、APScheduler v4 调度、Telegram 通知,均有抽象接口可替换

前置条件

必须先安装 Claude Code CLI

npm install -g @anthropic-ai/claude-code
claude --version   # 验证安装成功

安装

pip install harness-ai[cli]

或从源码安装(开发模式):

git clone https://github.com/woneway/Harness
cd Harness
pip install -e ".[dev,cli]"

快速上手

所有 harness 调用必须在 async 函数中执行:

import asyncio
from harness import Harness, LLMTask, FunctionTask, ShellTask

async def main():
    h = Harness(project_path=".")

    # 单次 LLM 调用
    result = await h.run("分析并修复代码质量问题")
    print(result.output)

    # 多步混合流水线
    results = await h.pipeline([
        FunctionTask(fn=collect_data),
        LLMTask("分析数据,给出优化建议"),
        ShellTask(cmd="pytest tests/"),
    ])

asyncio.run(main())

Task 类型

类型 用途
LLMTask 调用语言模型(默认 Claude Code CLI)
FunctionTask 执行 Python 函数
ShellTask 执行 Shell 命令
PollingTask 提交异步任务后轮询(视频生成、TTS 等)
Parallel 并发执行多个 Task

特性

  • 断点续跑pipeline(tasks, resume_from=run_id) 跳过已成功步骤
  • 自动重试:指数退避,可配置 max_retriesbackoff_base
  • 定时调度h.schedule(tasks, cron="0 2 * * *"); await h.start()
  • Memory 注入:历史运行摘要 + memory.md 自动注入给 LLMTask
  • 流式输出stream_callback 实时接收 Claude 输出

示例

# 克隆项目后在项目根目录运行
uv run python examples/code_stats/main.py               # 统计代码量(FunctionTask + LLMTask + ShellTask)
uv run python examples/analyze_harness/main.py          # 分析 → 优化 → 复盘(三阶段 pipeline)
uv run python examples/research_report/main.py Clawith  # 联网调研报告(多 LLMTask + FunctionTask)
uv run python examples/video_pipeline/main.py           # LLMTask + Parallel[PollingTask×2] + FunctionTask
uv run python examples/poker_debate/main.py             # 德扑五方辩论(Dialogue 回合模式)

CLI

harness runs           # 列出最近运行记录
harness runs --failed  # 只看失败的
harness migrate --to "postgresql+asyncpg://..."  # 迁移数据库

设计文档

详见 design/v1-design.md

许可证

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

harness_ai-0.1.0.tar.gz (144.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

harness_ai-0.1.0-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file harness_ai-0.1.0.tar.gz.

File metadata

  • Download URL: harness_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 144.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for harness_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c628db86724613d927055f90fe11516d11725b8e955d936933309918c89d6867
MD5 5ff0cdb55f237512c79463a88c636d81
BLAKE2b-256 824fb19f152eee074d9abb880987740b2ce0e42bea8ac9f0a2b6c00891674cf2

See more details on using hashes here.

File details

Details for the file harness_ai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: harness_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for harness_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6acf46586661b8c1ce9db433e272e8ade8194ed2fc3ef360f60cfc9bcce0e08b
MD5 b4c1a6e40754abaff36c05dbd382fd95
BLAKE2b-256 538f3919575ea994d9744b236b26e3764869643128e8d543ffa1d705839d9a12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page