SDK

Harness & pipelines

Generate the staged GitHub Actions pipeline from code — the same harness the CLI's setup command produces.

The harness turns a GitHub repo into a pipeline where labels drive an agent from issue to merged PR. Each stage is a label; promoting a label triggers the next workflow. The Harness class builds those workflows programmatically.

Building a pipeline

from harnext import Harness

harness = Harness(repo=".", provider="anthropic")

harness.setup(
    stages=["triage", "plan", "implement", "review"],
    runner="self-hosted",          # or "github"
    default_branch="main",
)

harness.write()                    # writes .github/workflows/*.yml + labels

Customizing stages

Add, reorder, or rewrite stages before writing. Each stage maps to a label, a prompt, and the agent settings used when it runs.

harness.add_stage(
    "security",
    after="review",
    prompt="Run a security review of the diff; block on high-severity findings.",
    provider="anthropic",
    permission_mode="plan",
)

harness.set_stage("implement", max_turns=60)
harness.remove_stage("triage")

harness.write()

Previewing without writing

Render the workflow files in memory to inspect or diff them in CI before committing.

files = harness.render()           # dict[path, contents]
for path, contents in files.items():
    print(path)

print(harness.diff())              # vs. what's currently on disk

Generated workflow

A stage workflow looks like this — one per stage label:

.github/workflows/stage-implement.yml
name: stage-implement
on:
  issues:
    types: [labeled]
jobs:
  run:
    if: github.event.label.name == 'stage:implement'
    runs-on: [self-hosted, harnext-9f4ac1b]
    steps:
      - uses: actions/checkout@v4
      - run: npm i -g harnext
      - run: harnext -p "Implement issue #${{ github.event.issue.number }}"
      - run: gh issue edit ${{ github.event.issue.number }}
              --remove-label stage:implement
              --add-label    stage:review
Same output as the CLI
Harness().setup().write() produces exactly what harnext setup writes. Use the CLI for a one-off; use the SDK when pipeline generation is itself part of an automated workflow.