# AI Agent Instructions: `.github/workflows/`

> Parent Instruction Chain
>
> 1. [agentic-devtools package instructions](../copilot-instructions.md)
>
> [`copilot-instructions.md` Precedence Model](../../docs/copilot-instructions-precedence-model.md)

## Scope

These instructions apply to Copilot and AI agents when writing or reviewing GitHub Actions
workflow files under `.github/workflows/`.

---

## 1. Strip Newlines from Values Written to `$GITHUB_OUTPUT`

When writing values sourced from JSON files, external data, or subprocess output into
`$GITHUB_OUTPUT`, strip CR and LF characters first. Embedded newlines break the
`key=value` line format and can inject additional output keys:

```bash
# ✅ CORRECT
base_sha=$(jq -r '.base_sha // ""' batch-meta.json | tr -d '\r\n')
echo "base_sha=${base_sha}" >> "$GITHUB_OUTPUT"

# ❌ WRONG — embedded newline splits the output into two lines, injecting a second key
echo "base_sha=$(jq -r '.base_sha' batch-meta.json)" >> "$GITHUB_OUTPUT"
```

This rule applies to every `echo "key=value" >> "$GITHUB_OUTPUT"` line where the value
is derived from external data (API responses, JSON files, subprocess stdout).

**Based on audit of PR:** #2517
