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
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Non-secret identifiers only. Never add tokens or private keys here.
APP_ID=
APP_INSTALLATION_ID=
# Configuration names only. Supply values through the environment, not this file.
# The publisher does not load .env automatically. Never add key contents or tokens.
GITHUB_APP_ID=
GITHUB_APP_PRIVATE_KEY_PATH=
14 changes: 13 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@ This workspace is **github-agent-contracts** only.
- Edit no paths outside this repository.
- Do not request or embed credentials.
- Prefer Node 20 ESM scripts with zero dependencies.
- Agent commits in *other* consumer repos should use trailers from `docs/commit-trailers.md`. Commits *to this repo* during bootstrap may be human-authored without trailers.
- Agents must commit and publish through `node scripts/agent-pr.mjs`, never raw `git commit`, `git push`, or a separate `gh pr create`. Never commit as R4yHarris or use a human token as a fallback.
- Follow `skills/signed-bot-commit/SKILL.md`. App environment variables never authorize use of the signed-in human's identity, and missing App configuration means stop. Never merge or enable auto-merge.
- Invoke the helper only after authorization for commit, push, and a draft PR. A request to stop after writing files and testing means no publication. 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.
- 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.

Authorized publication example:

```bash
node scripts/agent-pr.mjs --message "docs: clarify agent contracts" --model unknown --files README.md
```
22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ Reusable conventions and small tools so Copilot, GitHub Agentic Workflows (`gh-a
- Do not grant agents `admin`, `delete`, or unscoped `repo` power in examples.
- Default writes on GitHub are **safe outputs only**: comments, labels, draft PRs — never force-push, never merge without a human.

## Agent publication

- Follow `skills/signed-bot-commit/SKILL.md` for all publishing. The security control is the required PR check plus protected branch, bot author, and trailers; an App installation supplies authentication, not a merge exemption.
- Agents must use `node scripts/agent-pr.mjs` for commits and publication in this repository. Do not run raw `git commit`, `git push`, or a separate `gh pr create`, and never commit as R4yHarris or fall back to a human's credentials.
- If App environment variables are set, never commit or push as the signed-in human. If they are missing, stop rather than falling back. Their presence is not authorization to publish.
- Run the script only when the human has authorized committing, pushing the current feature branch, and creating a draft PR. If told to stop after editing or testing, do not invoke it.
- 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.
- Without `--files`, it commits the reviewed staged changes. With `--files`, pass individual repository files last; unrelated staged files cause a failure. 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 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.
- Require the `check-agent-trailers` check on protected branches, forbid direct agent pushes or bypass, and leave every merge to a human. Never enable auto-merge or merge a PR yourself.
- 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
```

## Day-1 build targets

Implement what `docs/DAY1_SCOPE.md` lists. Prefer small, tested files.
Expand All @@ -34,6 +53,9 @@ Implement what `docs/DAY1_SCOPE.md` lists. Prefer small, tested files.
node scripts/check-agent-trailers.mjs --help
node scripts/check-agent-trailers.mjs --message-file path/to/msg.txt

# Publication help only; this does not read a key or contact GitHub
node scripts/agent-pr.mjs --help

# Tests
node --test tests/*.test.mjs
```
Expand Down
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Repository instructions

Follow [AGENTS.md](AGENTS.md) for all repository rules and required skills.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# github-agent-contracts

GitHub-native contracts for coding agents. **GitHub stays the repository host.** This library does not replace Git, GitHub, or an orchestrator.
GitHub-native contracts for attributable agent commits and PRs, distinct from human-authored work. **GitHub stays the repository host.** The control is a required PR check, a protected branch, bot authorship, and machine-checked trailers. The App is how agents authenticate to GitHub.

This is community OSS for GitHub, not a GitHub replacement.

## Enable agent identity in 3 steps

1. **[Register App from manifest](docs/app-manifest.json).** Create an App owned by you or your organization, keep it private to that account, and choose **Only select repositories** during installation.
2. **Configure and copy.** Supply `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY_PATH` outside git, then copy AGENTS.md, the signed-bot-commit skill, publisher, and check Action/workflow as listed in [ONBOARDING.md](docs/ONBOARDING.md). CI stores the key in the `GITHUB_APP_PRIVATE_KEY` secret.
3. **Protect and publish.** Require `check-agent-trailers`, disallow direct pushes to `main` and agent bypass, and reserve merges for humans. Tell the agent: "Use signed-bot-commit / scripts/agent-pr.mjs for all publish."

The manifest is a static template, not a hosted registration button. An owner-controlled manifest callback is a follow-on; placeholder URLs must be replaced before completing GitHub's flow. The [onboarding guide](docs/ONBOARDING.md) describes that boundary and the manual registration fallback.

### Create your own App (recommended)

Your account or organization owns the App and controls its private key. No project-maintainer installation is needed. Use the [manifest](docs/app-manifest.json), [harness guide](docs/HARNESSES.md), and [threat model](docs/THREAT_MODEL.md). The App key holder can mint tokens for **every installation of that App**, so installation scope and key custody matter.

### Demo App

`r4yharris-agent-coder` is an optional maintainer demo identity for **public playground repositories only**. Do not install it on private or production repositories or grant it protected-branch bypass. A globally shared maintainer App is not this standard's production onboarding model.

## Shared contracts

Use it so Copilot, [GitHub Agentic Workflows](https://github.com/github/gh-aw), Hermes, Codex, Cursor, and similar tools share one repo-level convention:

| Contract | Where |
Expand All @@ -21,13 +39,16 @@ Humans can review the same rules agents follow, while commit trailers make claim

## Consume the contracts

- **Copilot / VS Code:** keep [AGENTS.md](AGENTS.md) at the repository root and [.github/copilot-instructions.md](.github/copilot-instructions.md) in place. Copy selected `skills/<name>/` directories into `.github/skills/` in the consuming repository for skill discovery in supported versions.
- **Copilot / VS Code:** use [AGENTS.md](AGENTS.md) and [.github/copilot-instructions.md](.github/copilot-instructions.md) only as harness configuration. They reference the common commit skill and publisher; no additional agent mode or skill autodiscovery setup is required.
- **Claude Code:** use the short [CLAUDE.md](CLAUDE.md) pointer to AGENTS.md, not a duplicate policy.
- **gh-aw:** include the repository rules and relevant skills in the workflow's instructions. Start with the [issue clarifier source](.github/workflows-src/issue-clarifier.md); the agent is read-only and can request only an `add-comment` safe output.
- **Hermes, Codex, and other agents:** load `AGENTS.md` as repository instructions and import the selected `SKILL.md` files using that runtime's skill mechanism. Discovery paths differ by runtime; this pack does not patch those runtimes.
- **GitHub MCP:** use the [allowlist skill](skills/github-mcp-allowlist/SKILL.md) with a repository-scoped GitHub App installation token. Keep the agent's tools read-only; give approved output handlers only the capabilities they need.

Adapt the workspace-specific names in the instruction files when adopting the pack. Human approval, scoped permissions, and tool restrictions enforce boundaries; prompts alone do not.

See [HARNESSES.md](docs/HARNESSES.md) for the minimal integration in each runtime. Any agent that honors AGENTS.md must honor signed-bot-commit.

## Use in another repo

Follow the [adoption guide](docs/adopt.md) and copy the [consumer workflow](examples/consumer-repo/.github/workflows/check-agent-trailers.yml). Reference the pinned public Action without copying scripts, or vendor the Action and both scripts together. No package registry or GitHub App credentials are needed for the trailer check.
Expand Down Expand Up @@ -59,7 +80,7 @@ AI-Model: unknown

The default checks messages containing `AI-Agent:` and GitHub noreply bot authors. Human privacy addresses alone do not trigger a check. For local author detection, pass `--author-email`; `--require` checks every message. Exit codes are `0` (pass), `1` (missing trailers), and `2` (usage or input error).

See the [trailer spec](docs/commit-trailers.md) for parsing rules, limitations, and the Action's `require-on-all-commits: "true"` option.
See the [trailer spec](docs/commit-trailers.md) for parsing rules and the Action's `require-on-all-commits: "true"` option. The [threat model](docs/THREAT_MODEL.md) explains why trailers and bot fields do not prove authorship, and why unsigned human commits pass the default check.

## PR workflow

Expand All @@ -81,6 +102,8 @@ Review the generated workflow and configure the chosen engine's authentication o

From the local repository root, after creating an empty GitHub repository:

These bootstrap commands are for a **human**. Agents must use the App-authenticated publication helper and never assume the human's identity.

```bash
git init -b main
git add .
Expand Down
2 changes: 1 addition & 1 deletion docs/DAY1_SCOPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Build only this. Stop when the checklist is green.
- `skills/github-mcp-allowlist/SKILL.md`
- `skills/pr-safe-outputs/SKILL.md`
8. One `gh-aw` **source** workflow: `.github/workflows-src/issue-clarifier.md` (read-all, `safe-outputs.add-comment` only).
9. `.env.example` listing names of env vars only (`APP_ID`, `APP_INSTALLATION_ID`, empty values).
9. `.env.example` listing names of env vars only (`GITHUB_APP_ID`, `GITHUB_APP_PRIVATE_KEY_PATH`, empty values).

## Out

Expand Down
27 changes: 27 additions & 0 deletions docs/HARNESSES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Harnesses

The common contract is [AGENTS.md](../AGENTS.md), which requires [signed-bot-commit](../skills/signed-bot-commit/SKILL.md) and [scripts/agent-pr.mjs](../scripts/agent-pr.mjs) for authorized publication. Use the consuming user's or organization's App from [ONBOARDING.md](ONBOARDING.md), never a shared maintainer App for private repositories.

Harness setup does not replace the required `check-agent-trailers` check, branch protection, bot authorship, or trailers. No harness may publish as the signed-in human, print credentials, or merge an agent PR. App environment variables do not themselves authorize publication.

## Copilot

Use **AGENTS.md + .github/copilot-instructions.md only** as the Copilot configuration. The Copilot file points to the common repository rules, and those rules point to the commit skill and publisher. No custom agent mode, extra prompt file, or MCP server is required for publishing.

The referenced skill file and scripts must still be present. Do not rely on harness-specific skill autodiscovery to enforce the common contract, and do not duplicate a competing publication policy in another Copilot configuration.

## Claude Code

Keep [CLAUDE.md](../CLAUDE.md) as a short pointer to AGENTS.md. Claude Code reads that pointer, then follows the same commit skill and publishing script. Do not copy the full policy into both files or add Claude-specific credentials.

## Hermes

Load AGENTS.md as repository instructions and [skills/signed-bot-commit/SKILL.md](../skills/signed-bot-commit/SKILL.md) as the publication skill using the installed runtime's supported mechanism. For GitHub issue, PR, or code reads, also follow the [GitHub MCP allowlist skill](../skills/github-mcp-allowlist/SKILL.md).

Use repository-scoped installation tokens supplied by a trusted launcher; never store tokens in repository MCP configuration. Keep default agent tools read-only and write-capable credentials in the approved publication context. No Hermes runtime changes are needed.

## Generic agents

If you honor **AGENTS.md**, you honor **signed-bot-commit**. Read the referenced skill and invoke the same helper after explicit authorization, regardless of whether your runtime has a native skill loader.

When the necessary instructions, App environment, or publishing tools are unavailable, stop and report the missing prerequisite. Do not fall back to raw Git, human credentials, or automatic merging. Humans review and merge.
Loading
Loading