
Transcript
An unattended PanCode run with JSON output
Recorded with PanCode 0.9.1. Each section is the terminal screen at that moment.
== answer
~/projects/calibration-lab $ pancode run --output-format stream-json "Run the test check and report how many tests pass." > run.jsonl; echo "exit $?"
exit 0
~/projects/calibration-lab $ jq -r 'select(.type == "run_end").result.text' run.jsonl
The test check reports 6 passing tests and 1 failure. The failing test is “absolute zero”: `kelvinToCelsius(0)` throws `RangeError`.
~/projects/calibration-lab $
== run-end
"tools": {
"calls": 3,
"refused": 0,
"writes": 0
},
"safety": {
"decisions": {
"allowed": 3,
"blocked": 0,
"guardBlocked": 0,
"permissionRequested": 0
},
"blockedAttempts": []
},
"verify": {
"requested": 0,
"checks": []
},
"dispatch": {
"runs": [],
"live": [],
"undelivered": []
},
"timings": {
"sessionReadyMs": 938,
"firstRequestMs": 2212,
"firstTokenMs": 5320
}
}
~/projects/calibration-lab $On this page
Before you start Build the job step by step Exit codes a job can branch on A GitHub Actions job Limits to know NextA CI job needs three things from a coding agent: a result it can parse, an exit code it can branch on, and limits it can rely on. pancode run gives a script all three. This guide builds one job step by step, then puts it in a GitHub Actions workflow.
Before you start
- PanCode installed on the runner, with a model connection whose key comes from an environment variable.
- A repository with a test command.
jq, to read the result.
Build the job step by step
Preview the run without calling a model
--dry-runprints what the run would do and exits 0. It opens no session, calls no model, and runs no check.Shell
pancode run --dry-run --output-format json \ --max-cost-usd 2 --timeout 15m \ --verify "npm test" \ "Fix the failing parser test." | jq '.plan'The plan names the route, the tools the agent may use, the sandbox mode, the limits, and the checks. Put this in a pull request job to catch a bad flag before anything is spent. Check that
.plan.route.connectionis set.Ask for one result document
--output-format jsonprints onerun_enddocument on stdout when the run is over. Progress and notices go to stderr, so stdout is the document alone.Shell
pancode run --output-format json \ --max-cost-usd 2 --timeout 15m \ "Fix the failing parser test." > result.jsonUse
--output-format stream-jsoninstead when another program should follow the run live. It prints one JSON event per line and ends with the samerun_enddocument.Bound the run
Each limit is a flag, and each one stops the run with its own cause code.
Shell
pancode run --output-format json \ --max-requests 40 --max-tool-calls 120 \ --max-cost-usd 2 --require-priced \ --timeout 15m --sandbox required \ "Fix the failing parser test." > result.json--max-requestsand--max-tool-callscap the main agent's model requests and tool calls.--max-cost-usdcaps priced spend, and--require-pricedrefuses the run when a route it could reach has no price.--sandbox requiredrefuses to start on a runner with no OS sandbox.Make the job fail when the work is not finished
By default a run that ends normally exits 0, whatever the agent says about its own work. Two flags turn an honest "not finished" into a failed job.
Shell
pancode run --output-format json \ --verify "npm test" --fail-on-verify \ --exit-code \ "Fix the failing parser test." > result.json--verifydeclares an acceptance check that PanCode runs itself after the turn, and--fail-on-verifyexits 1 when it fails.--exit-codeexits 1 when the run was assessed as partly done or not done.The agent declares how the turn ended, and PanCode records that claim beside its own assessment. A claim of done that left unvalidated changes or a failing check is assessed as partly done, so
--exit-codefails it.Get a structured answer
When the next step needs data instead of prose, pass a JSON Schema. The answer must be one JSON object that matches it, and PanCode validates the object before the run exits 0.
Shell
cat > summary.schema.json <<'EOF' { "type": "object", "required": ["fixed", "files"], "properties": { "fixed": { "type": "boolean" }, "files": { "type": "array", "items": { "type": "string" } } } } EOF pancode run --output-format json \ --output-schema summary.schema.json \ "Fix the failing parser test and report which files changed." \ | jq '.result.structured'A mismatch gets one repair turn with no tools. If the answer still does not match, the run exits 1 with cause
schema_mismatch. The schema's root must be an object, and a schema PanCode cannot enforce exits 2 before any model request.Read the result
Branch on the exit code first, then read the fields you need.
Shell
jq -r '.outcome' result.json # succeeded, failed, canceled, timed_out jq -r '.causes[].code' result.json # why, most important first jq -r '.result.text' result.json # the answer jq '.verify.checks' result.json # each --verify check and whether it passed jq '.usage.total' result.json # tokens and costcausesis empty on success. On a failure or a stop it lists every reason as a code, usually with a message.-o answer.mdalso writes the answer to a file when the run exits 0.
What you should see
One JSON document on stdout, an exit code that matches its exitCode field, and a causes list that names the reason whenever that code is not 0.
Exit codes a job can branch on
| Exit | Meaning | Typical cause codes |
|---|---|---|
0 |
The run settled and succeeded | none |
1 |
The run failed, or a flag you set turned an unfinished result into a failure | verify_failed, schema_mismatch, context_overflow |
2 |
A usage or setup error, before any model request | empty_task, schema_unsupported, session_live |
3 |
A request nobody could approve, with --on-permission fail |
permission_required |
4 |
A limit stopped the run | max_requests, max_tool_calls, max_cost_usd |
124 |
--timeout expired |
deadline |
Retry on 124 or 4 only after you raise the limit, because the same run will stop at the same place. An exit of 2 is a mistake in the job itself, so fail fast and fix the command.
A GitHub Actions job
This workflow installs PanCode, connects a model from a repository secret, previews the run, then runs it with limits. The job fails when the run does not finish the work.
YAML
name: agent-fix
on: workflow_dispatch
jobs:
fix:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
steps:
- uses: actions/checkout@v4
- name: Install PanCode
run: |
curl -fsSL https://pancode.dev/install.sh | sh -s -- --no-gui
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Connect a model
run: |
pancode configure --id ci --runtime anthropic \
--model <model> --api-key-env ANTHROPIC_API_KEY --set-orchestrator
- name: Preview
run: |
pancode run --dry-run --output-format json \
--verify "npm test" "Fix the failing parser test." | jq '.plan'
- name: Run
run: |
pancode run --output-format json \
--max-requests 40 --max-cost-usd 2 --timeout 15m \
--verify "npm test" --fail-on-verify --exit-code \
"Fix the failing parser test." > result.json
- name: Report
if: always()
run: |
jq -r '"outcome: \(.outcome)", "causes: \([.causes[].code] | join(", "))"' result.json
jq -r '.result.text' result.json >> "$GITHUB_STEP_SUMMARY"Replace <model> with a model id from pancode models --connection ci. The key stays in the secret: --api-key-env names the variable, and PanCode reads it when it calls the model. If the installer put the launcher somewhere else, command -v pancode after the install step shows where.
Limits to know
A headless run has no one to ask. Requests that would need approval are denied, and the turn goes on without them unless you pass --on-permission fail.
--max-cost-usd bounds priced routes only. On a route with no price, stderr says the cap cannot bound it, and --require-priced turns that into a refusal.
Pass the task as an argument. run reads stdin only when you pass -, so a pipe into run without it is ignored.
Next
Run it unattended within limits covers read-only runs, yolo, and scheduled turns. The exit codes and output guide lists every field and cause.