Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This workspace is **github-agent-contracts** only.
- After reviewing/staging files, passing tests and policy gates, invoke the helper as the final step only after authorization for commit, push, and a draft PR. A request to stop after writing files and testing means no publication. Missing App configuration means leave changes uncommitted after tests. Humans may perform their own bootstrap commits.
- The human supplies `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY_PATH` in the environment. Do not read the PEM into chat, print tokens, or stage/commit `.env` or key files; the helper does not load `.env`.
- Use the consuming user/org's own App through `docs/ONBOARDING.md` and `docs/app-manifest.json`; do not recommend the maintainer demo App for private or production repositories.
- The helper discovers the configured App's verified bot identity for author and committer and uses its slug in `AI-Agent`. `--model` defaults to `unknown`; `--files` must be last. Without it, only reviewed staged changes are committed.
- The helper discovers the configured App's verified bot identity for author and committer and uses its slug in `AI-Agent`. Supply the actual model id through `--model` or `AI_MODEL`; there is no `unknown` fallback, and agents must not invent one. `--files` must be last. Without it, only reviewed staged changes are committed.
- Run tests first. On a missing prerequisite or failed publication, stop rather than falling back to raw Git; a partial failure can leave a valid local commit. Commits are unsigned, so do not invoke the helper when signing is required.
- Keep examples scoped: GitHub App installation tokens, MCP tool allowlists, `permissions: read-all` plus explicit safe-outputs.

Expand All @@ -24,5 +24,5 @@ Authorized publication example:
```bash
node scripts/load-agent-policy.mjs --role coder --capability commit_branch
node scripts/load-agent-policy.mjs --role coder --capability open_pr
node scripts/agent-pr.mjs --message "docs: clarify agent contracts" --model unknown --files README.md
node scripts/agent-pr.mjs --message "docs: clarify agent contracts" --model gpt-5 --files README.md
```
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ node scripts/load-agent-policy.mjs --role coder --capability open_pr
- Only use `--merge-when-green` when the human also authorizes merging and remote feature-branch deletion. A human must first add `merge` to `roles.merger.allow` in root `agent-policy.yml` and publish that grant on the default branch. Never edit the policy yourself or treat the flag as a grant. Keep the flag disabled on coder-only WSL; a trusted launcher/operator must use a separately approved merger App/context for merging.
- The human supplies `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY_PATH` through the environment. Never read the PEM into chat, paste key material, print tokens, or commit `.env` or private-key files. The script does not load `.env` automatically.
- Default onboarding is a user/org-owned App from `docs/app-manifest.json`; follow `docs/ONBOARDING.md` and `docs/THREAT_MODEL.md`. Never recommend the maintainer's `r4yharris-agent-coder` App for private or production repositories; a demo install is for public playgrounds only.
- The helper verifies origin's installation against `GITHUB_APP_ID`, resolves that App's bot account, sets both author and committer to it, and adds `AI-Agent: <app-slug>` plus `AI-Model: unknown`. Do not hard-code or invent a bot identity; use `--model` when the model is known.
- The helper verifies origin's installation against `GITHUB_APP_ID`, resolves that App's bot account, sets both author and committer to it, and adds `AI-Agent: <app-slug>` plus the actual `AI-Model` id from `--model` or `AI_MODEL`. Neither has an `unknown` fallback; if the model is unavailable, stop without publishing. Do not hard-code or invent a bot identity or model.
- Without `--files`, it commits the reviewed staged changes. With `--files`, pass individual repository files last; unrelated staged files cause a failure. Staged or selected `.github/workflows/**` paths are refused before token minting; a human must publish workflow changes. Inspect the changes and run the tests before publication.
- Node 20+, Git, and `gh` are required. The App must be installed on origin's repository with contents and pull requests write permissions; the opt-in merge flow also needs Checks read permission. The helper creates a repository-scoped installation token, pushes without force, creates a draft PR only if no open PR exists, and revokes the token.
- This is the explicitly authorized branch-publication path, not a general grant of GitHub write permissions. It refuses main, master, and the repository's default branch. Never bypass repository protections.
Expand All @@ -59,7 +59,7 @@ node scripts/load-agent-policy.mjs --role coder --capability open_pr
- Commits are unsigned for now. If signing is required or any step fails, stop and report it without a raw Git fallback. A human may commit a bootstrap slice themselves; agents may not assume that identity. After a partial failure, inspect the existing commit and PR before retrying.

```bash
node scripts/agent-pr.mjs --message "docs: clarify agent contracts" --model unknown --files README.md
node scripts/agent-pr.mjs --message "docs: clarify agent contracts" --model gpt-5 --files README.md
```

## Optional run metadata
Expand Down
2 changes: 1 addition & 1 deletion COPILOT_DAY1_PROMPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Required trailers when a commit is classified as agent-authored:

```
AI-Agent: <name>
AI-Model: <model or "unknown">
AI-Model: <actual model id; do not invent or use "unknown">
```

Recommended:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This is **not a git host, not `copilot[bot]`, not a personal access token (PAT),

The control is **required PR check + protected branch + bot author + trailers**. The App authenticates GitHub operations. App permissions, branch protection/environments, and the policy must all allow an action; installing an App or adding a prompt does not replace these gates.

The [publisher](scripts/agent-pr.mjs) discovers the configured App's bot, sets both author and committer, appends `AI-Agent` and `AI-Model`, pushes an authorized feature branch, and creates a draft PR if none exists. It uses `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY_PATH` from the environment, not a signed-in human's credentials. Missing configuration or denied policy means stop with changes uncommitted.
The [publisher](scripts/agent-pr.mjs) discovers the configured App's bot, sets both author and committer, appends `AI-Agent` and the actual `AI-Model` id, pushes an authorized feature branch, and creates a draft PR if none exists. Supply the model through `--model` or `AI_MODEL`; missing or placeholder values stop publication rather than inventing a model. It uses `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY_PATH` from the environment, not a signed-in human's credentials. Missing configuration or denied policy means stop with changes uncommitted.

Humans own policy and workflow changes. Agents cannot grant themselves capabilities or publish `.github/workflows/**` through this helper. Never force-push, push main directly, squash, or self-approve. Deploy and direct protected-push implementations are out of scope.

Expand Down Expand Up @@ -68,16 +68,16 @@ An agent commit has a blank-separated footer:

```text
AI-Agent: your-app-slug
AI-Model: unknown
AI-Model: gpt-5
```

The check inspects messages containing `AI-Agent:` and GitHub noreply bot authors by default. Unmarked human commits pass. `--require`, or the Action's `require-on-all-commits: "true"`, requires trailers on every commit. See the [trailer specification](docs/commit-trailers.md) for parsing, exit codes, and limits.
`gpt-5` is an example; use the actual model id for each run. The check inspects messages containing `AI-Agent:` and GitHub noreply bot authors by default, and rejects missing or placeholder models. Unmarked human commits pass. `--require`, or the Action's `require-on-all-commits: "true"`, requires trailers on every commit. See the [trailer specification](docs/commit-trailers.md) for parsing, exit codes, and limits.

The [PR workflow](.github/workflows/check-agent-trailers.yml) uses the trusted base revision's checker with full history and read-only permissions. Bootstrap the Action and scripts before enabling the local workflow. Humans must configure required checks, reviews, and branch protection; the script does not configure them.

## Optional run metadata (v0.2.0)

Harnesses can supply compact run information through the documented `AI_*` environment variables. The publisher adds one optional `AI-Run` trailer and upserts a tagged PR body pair; with no supplied metadata, publishing and the default two-trailer check remain unchanged. `--require-run` opts into validation. [METRICS.md](docs/METRICS.md) specifies the format, human-only `AI-Eval` comments, and local JSONL export with [export-agent-metrics.mjs](scripts/export-agent-metrics.mjs). No analytics service, prompts, traces, or generated quality scores are added.
Harnesses can supply compact run information through the documented `AI_*` environment variables. The publisher adds one optional `AI-Run` trailer and upserts a tagged PR body pair; with no supplied optional metadata (but with the required model id), publishing and the default two-trailer check remain unchanged. `--require-run` opts into validation. [METRICS.md](docs/METRICS.md) specifies the format, human-only `AI-Eval` comments, and local JSONL export with [export-agent-metrics.mjs](scripts/export-agent-metrics.mjs). No analytics service, prompts, traces, or generated quality scores are added.

## With gh-aw

Expand Down
12 changes: 6 additions & 6 deletions docs/METRICS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compact agent-run metadata

v0.2.0 adds one optional `AI-Run` trailer. The required `AI-Agent` and `AI-Model` trailers are unchanged. Run metadata is harness-supplied provenance, not proof of authorship, an analytics service, or a quality score. Do not put prompts, traces, credentials, or free-form notes in git.
v0.2.0 adds one optional `AI-Run` trailer. `AI-Agent` and `AI-Model` remain required; `AI-Model` must identify the actual model, not `unknown`. Run metadata is harness-supplied provenance, not proof of authorship, an analytics service, or a quality score. Do not put prompts, traces, credentials, or free-form notes in git.

## Schema 1

Expand All @@ -27,9 +27,9 @@ AI-Run: 1|anthropic|claude-sonnet-4.5@20250901|h|18234/200000|2510|ses_01K8|feat
| 7: session | Opaque `[A-Za-z0-9._-]{1,64}` identifier |
| 8: task | Opaque `[A-Za-z0-9._-]{1,64}` identifier |

Use `-` as the missing-value sentinel for provider, effort, counts, session, and task. It is not another provider or effort level. A missing version is `unknown`, giving `<model>@unknown`. The required `AI-Model` retains its existing `unknown` fallback; when only a provider is supplied, column 3 is `unknown@unknown`.
Use `-` as the missing-value sentinel for provider, effort, counts, session, and task. It is not another provider or effort level. A missing version is `unknown`, giving `<model>@unknown`. A missing model is not a metadata slot: the publisher refuses to create an agent commit without the actual model id.

Keep all eight columns, with no spaces around `|`. Model names are single-line tokens; they may include a provider path such as `owner/model`, but cannot contain whitespace, `|`, `@`, or backticks. No field supplied by the harness may contain a pipe. Session and task identifiers must not contain personal data or secrets.
Keep all eight columns, with no spaces around `|`. Model ids are single-line tokens starting with a letter or digit and may contain letters, digits, `.`, `_`, `-`, `:`, `/`, or `+`, including a provider path such as `owner/model`. Placeholders and whitespace, `|`, `@`, or backticks are invalid. No field supplied by the harness may contain a pipe. Session and task identifiers must not contain personal data or secrets.

Parsers ignore extra trailing `|fields` for forward compatibility. Unknown unrelated trailer keys are ignored. When a schema-bearing `AI-Run` is present, invalid columns 1-8 cause a parse error; unsupported schemas are errors too. An absent or empty `AI-Run` has no schema and produces no record. Extra fields do not rescue invalid known columns. There is no `AI-X-*` family or additional YAML document.

Expand All @@ -40,7 +40,7 @@ Export only values actually reported by the harness before invoking [agent-pr.mj
| Environment variable | Stored value | When missing |
| --- | --- | --- |
| `AI_PROVIDER` | Provider from the allowed list | `-` |
| `AI_MODEL` | Required `AI-Model` and model part of column 3 | `unknown` in the required trailer |
| `AI_MODEL` | Required `AI-Model` and model part of column 3 | Supply `--model` or publishing exits `2` |
| `AI_MODEL_VERSION` | Version token in column 3 | `unknown` |
| `AI_EFFORT` | `low`/`l` -> `l`, `medium`/`m` -> `m`, `high`/`h` -> `h`, `max`/`x` -> `x` | `-` |
| `AI_CONTEXT_USED` | `in` | `-` |
Expand All @@ -49,9 +49,9 @@ Export only values actually reported by the harness before invoking [agent-pr.mj
| `AI_SESSION` | Session identifier | `-` |
| `AI_TASK` | Task identifier | `-` |

`--model` takes precedence over `AI_MODEL`; both the required trailer and `AI-Run` use the selected model. If all nine variables are unset or empty, no `AI-Run` is written, even with `--model`. `AI_MODEL` alone counts as environment input. If some variables are supplied, keep the trailer with missing-slot sentinels unless both provider and the explicitly supplied model are empty. Do not invent identity information just to emit a record. Malformed supplied values, including an unknown effort, are rejected before key access or GitHub requests.
`--model` takes precedence over `AI_MODEL`; both the required trailer and `AI-Run` use the selected model. The publisher exits `2` if neither supplies a valid model id; it never invents one. If all nine variables are unset or empty, no `AI-Run` is written, even with `--model`. `AI_MODEL` alone counts as environment input. With run input and a known model, missing slots use sentinels. Do not invent identity information just to emit a record. Malformed supplied values, including an unknown effort, are rejected before key access or GitHub requests.

For example, provider-only input `AI_PROVIDER=local` produces `1|local|unknown@unknown|-|-/-|-|-|-`. Model-only input `AI_MODEL=known-model` produces `1|-|known-model@unknown|-|-/-|-|-|-`. Counts of zero stay `0`, not `-`.
For example, `AI_PROVIDER=local` with `--model gpt-5` produces `1|local|gpt-5@unknown|-|-/-|-|-|-`. Model-only input `AI_MODEL=known-model` produces `1|-|known-model@unknown|-|-/-|-|-|-`. Counts of zero stay `0`, not `-`. The `unknown` suffix is a missing model **version**, not a missing model id.

## PR body

Expand Down
4 changes: 2 additions & 2 deletions docs/adopt.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Agent-classified commits need a blank-separated footer such as:
feat: add input validation

AI-Agent: copilot-coding-agent
AI-Model: unknown
AI-Model: gpt-5
```

To require trailers on human commits too, set this input in the Action step's `with:` block:
Expand All @@ -72,7 +72,7 @@ To require trailers on human commits too, set this input in the Action step's `w
require-on-all-commits: "true"
```

The default is `"false"`. Missing required trailers fail the check, as do invalid commit ranges or incomplete history. Trailers and author emails are provenance claims, not proof of identity or authorization to write to GitHub.
The default is `"false"`. Missing required trailers and placeholder models fail the check, as do invalid commit ranges or incomplete history. `gpt-5` above is an example; use the model id actually reported by the harness. Trailers and author emails are provenance claims, not proof of identity or authorization to write to GitHub.

Before requiring the check, verify a PR with valid trailers passes and a marked agent commit missing `AI-Model` fails. In the default mode, an unmarked human commit should pass; in require-all mode, it should fail. Every commit in the PR must satisfy the selected policy, not just the latest commit.

Expand Down
Loading
Loading