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 @@ -8,10 +8,10 @@ This workspace is **github-agent-contracts** only.
- Prefer Node 20 ESM scripts with zero dependencies.
- Load root `agent-policy.yml` through `scripts/load-agent-policy.mjs` and follow `skills/agent-policy/SKILL.md` before publication or GitHub writes. Missing or invalid policy denies all actions; never fall back to the example or a different role.
- Agents must not edit, create, replace, or delete `agent-policy.yml` to grant themselves rights, or modify the executor to bypass a denial. A human reviews and publishes active policy changes.
- App permissions, branch protection/environments, and policy are cumulative gates. The coder publisher requires `commit_branch` and `open_pr`, checks the reviewed default-branch policy, and has no merge/protected-push/deploy or role-override mode. Humans merge; no deploys.
- App permissions, branch protection/environments, and policy are cumulative gates. The coder publisher requires `commit_branch` and `open_pr`, checks the reviewed default-branch policy, and has no protected-push/deploy or role-override mode. Human-only merge is the default; `--merge-when-green` additionally requires a human-published coder `merge` grant and explicit authorization for merge and remote-branch cleanup.
- Follow `docs/ROLES.md`: use separate role Apps, and keep only the coder key on the WSL orchestration host. Never use merger/deploy credentials or a human token there.
- 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.
- 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 self-approve, squash, push main, or enable GitHub auto-merge. The authorized merge flag must verify `check-agent-trailers` on the exact head SHA and honor all required reviews.
- 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.
Expand Down
10 changes: 6 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ Reusable conventions and small tools so Copilot, GitHub Agentic Workflows (`gh-a
- Do not invent a new git server, object store, or identity protocol.
- Do not put personal access tokens, Copilot tokens, or App private keys in the repo.
- 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.
- Default writes on GitHub are **safe outputs only**: comments, labels, draft PRs. Never force-push. Merging requires explicit human authorization, a human-reviewed policy grant, and the opt-in flow below.

## Capability policy

- Follow `skills/agent-policy/SKILL.md` and load root `agent-policy.yml` with `scripts/load-agent-policy.mjs` before publication or any GitHub write, including safe outputs. Missing or invalid policy denies every capability; never fall back to the example.
- App permissions, branch protection/environments, and the policy allow-list must all permit an action. A task prompt, available tool, App environment variable, or broader token does not override a denial.
- Agents must not create, edit, replace, or delete root `agent-policy.yml` to grant themselves rights. Humans review and publish policy changes. Do not bypass policy by changing the loader, publisher, or harness configuration.
- The publisher is fixed to coder and requires `commit_branch` plus `open_pr`, matching the reviewed default-branch policy. There is no role or policy-path override. Merge, protected pushes, and deploys are unsupported by the coder publisher; humans merge and deployments remain disabled.
- The publisher is fixed to coder and requires `commit_branch` plus `open_pr`, matching the reviewed default-branch policy. There is no role or policy-path override. `--merge-when-green` also requires `merge` in that same role; a merger-role grant does not authorize coder. Human-only merge remains the default. Protected pushes and deploys remain unsupported.
- Use separate user/org-owned role Apps. The WSL orchestration host holds only the coder key, never merger/deploy keys or human fallback credentials. Follow `docs/POLICY.md` and `docs/ROLES.md`.

```bash
Expand All @@ -42,13 +42,15 @@ node scripts/load-agent-policy.mjs --role coder --capability open_pr
- 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.
- Only use `--merge-when-green` when the human also authorizes merging and remote feature-branch deletion. A human must first allow `merge` in root `agent-policy.yml`, using `roles.coder.allow` in this policy format, and publish that grant on the default branch. Never edit the policy yourself or treat the flag as a grant.
- 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.
- 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.
- 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.
- Require the `check-agent-trailers` check on protected branches and forbid direct agent pushes or bypass. By default, leave merges to humans. The sole script-managed exception is authorized `--merge-when-green`: require a successful GitHub Actions check on the exact head SHA and all repository merge requirements, then create a merge commit and delete only the unchanged remote feature branch.
- Never self-approve, squash, rebase-merge, force-push, push main, or enable GitHub auto-merge. Marking an authorized draft ready does not approve it or bypass required human reviews. See `docs/POLICY.md` for polling, permission, and failure details.
- 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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Follow the [adoption guide](docs/adopt.md) and copy the [consumer workflow](exam

Hermes, Copilot, Claude Code, and Cursor share one human-owned root `agent-policy.yml`. The [example](examples/agent-policy.yml) allows coder branch commits, draft PRs, comments, and labels; merger and deploy allow-lists are empty. Missing policy denies publication, and agents must not edit policy to grant themselves rights.

Read [POLICY.md](docs/POLICY.md) for the three permission layers and human bootstrap, and [ROLES.md](docs/ROLES.md) for separate role Apps and a WSL host holding only the coder key. The coder publisher has no merge, protected-push, or deployment mode. No active root policy or hosted control plane is installed by this pack.
Read [POLICY.md](docs/POLICY.md) for the three permission layers, human bootstrap, and optional `--merge-when-green` flow, and [ROLES.md](docs/ROLES.md) for role-key separation. Merging remains disabled unless a human grants coder `merge` and authorizes the flag; it requires a successful exact-head trailer check and creates a merge commit before remote-branch cleanup. Protected pushes and deploys remain unsupported. No active policy grant or hosted control plane is installed by this pack.

## Non-goals

Expand Down
45 changes: 41 additions & 4 deletions docs/POLICY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ roles:
| `open_pr` | Open a draft PR or update its branch through the publisher | Coder only |
| `comment` | Request an approved comment output | Coder only |
| `label` | Request approved label changes | Coder only |
| `merge` | Merge a PR or enable automatic merging | Denied |
| `merge` | Permit the explicitly authorized `--merge-when-green` flow | Denied |
| `push_protected` | Directly update a protected branch | Denied |
| `deploy` | Start a deployment or use deployment credentials | Denied |

Expand Down Expand Up @@ -82,15 +82,52 @@ Unsupported YAML is rejected rather than interpreted permissively. Use the suppl

## Publisher enforcement

[agent-pr.mjs](../scripts/agent-pr.mjs) is fixed to the **coder** role. It requires both `commit_branch` and `open_pr` before key access or Git commands, even when an existing PR might be reused. It has no `--role` or `--policy` override.
[agent-pr.mjs](../scripts/agent-pr.mjs) is fixed to the **coder** role. It requires both `commit_branch` and `open_pr` before key access or Git commands, even when an existing PR might be reused. With `--merge-when-green`, it also requires coder `merge` at that point and in the reviewed default-branch policy. It has no `--role` or `--policy` override.

After App authentication, it reads root policy from origin's default branch and requires its grants to match the local policy. It refuses staged or specified root-policy changes, checks the new commit for policy edits, and verifies the policy in the committed tree before pushing. A feature-branch or working-copy self-grant cannot replace the default branch's policy. API or validation failures stop publication, with no human-token fallback.

The helper checks both branch protection and active rules before committing and again before pushing. Any applicable rule is treated conservatively as protection. Failure to determine protection state denies publication, even if it is only an availability or permission problem.

The coder helper has **no merge, protected-push, or deployment implementation**. `--merge`, `--push-protected`, and `--deploy` are rejected; adding those capabilities to a policy does not turn them on. A protected push first requires `push_protected`, then remains unsupported by this helper even with a grant. There is no merger or deploy script shipped in this change. Keep their allow-lists empty and let humans merge.
The coder helper has **no protected-push or deployment implementation**. Bare `--merge`, `--push-protected`, and `--deploy` are rejected. A protected push first requires `push_protected`, then remains unsupported by this helper even with a grant. The only merge implementation is the explicitly opted-in, policy-gated flow below. There is no separate merger or deploy script; keep those roles' allow-lists empty by default.

Any future privileged executor would require a separately authorized implementation, a separately controlled role App, an explicit human-reviewed grant, and the branch or environment gates. It must not reuse the coder key or reinterpret a successful read-only policy check as authorization to execute. See [ROLES.md](ROLES.md).
## Opt-in merge

**Humans must set merge to allow in root `agent-policy.yml` before `--merge-when-green` works.** Version 1 expresses this by adding `merge` to `roles.coder.allow`, not by adding a literal `merge: allow` field, which the strict parser rejects. For example, a human may review and publish this policy:

```yaml
version: 1
default: deny
roles:
coder:
allow: [commit_branch, open_pr, comment, label, merge]
merger:
allow: []
deploy:
allow: []
```

This is an explicit expansion of the coder role, not the default example. A grant under `merger.allow` alone does not authorize the fixed coder publisher. Agents must not edit, stage, or commit the active policy to enable this flag. The local, committed, and reviewed default-branch policy must agree; the helper rechecks local and reviewed policy while waiting and immediately before merging.

The human must also approve **Checks: read-only** for the configured App installation. The flag requests `checks: read` on its repository-scoped token in addition to the normal contents/pull requests write permissions. Normal publishing does not request this extra permission, and the default App manifest is unchanged. The repository must permit merge commits and permit this App's PR merge without any rule bypass; required human reviews still apply.

After explicit human authorization for publication, merge, and remote-branch cleanup:

```bash
node scripts/load-agent-policy.mjs --role coder --capability merge
node scripts/agent-pr.mjs --message "fix: validate input" --merge-when-green --files README.md
```

`--files` remains last. The flag extends the normal commit/push/PR invocation; it does not choose another role or enable GitHub's server-side auto-merge feature. Without the flag, even an allowed merge capability leaves the PR unmerged.

The helper finds exactly one open PR for the published feature branch and verifies its repository, target branch, and head SHA. It polls every five seconds, with a ten-minute polling budget and at most 120 attempts, for `check-agent-trailers` from GitHub Actions on that **exact head SHA**. A successful run on an older commit or a synthetic merge SHA is not accepted. Missing or pending checks wait; completed failure, skipped, neutral, cancelled, or unknown results stop the flow. Incomplete results and API failures also stop it.

When the check is green, the helper may mark a draft PR ready, then rereads its head, checks, and mergeability. This is not a review or self-approval. It waits for GitHub to report the PR mergeable with a clean state; pending required reviews or other requirements eventually time out without merging. It never approves its own PR, changes protection rules, requests an admin bypass, or enables auto-merge.

Once eligible, it sends a SHA-guarded merge request with `merge_method: merge`, preserving provenance trailers in the merge commit message. It never squashes, rebase-merges, force-pushes, or pushes main directly. GitHub must still accept the merge under the repository's rules.

Only after GitHub confirms the merge does it delete the remote feature branch. It checks that the branch is still unprotected and still points to the published SHA before deletion; an already-deleted branch is treated as cleaned up. It never deletes the local branch. If a branch has advanced or cleanup fails, report the partial result rather than deleting new work or claiming full success. The reference check and deletion are separate API requests, so avoid concurrent writes to a branch being cleaned up.

On failure, the published commit and PR can remain, and a timed-out flow may have marked a draft ready. Inspect the PR and remote branch before retrying; do not create a duplicate commit just to retry a merge. Human-only merge remains the default, and deploys and direct protected pushes stay disabled. Prefer the separate-role model in [ROLES.md](ROLES.md) wherever granting coder merge authority is not acceptable.

## Limits

Expand Down
4 changes: 3 additions & 1 deletion docs/ROLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Use separate, user/org-owned GitHub Apps for **coder**, **merger**, and **deploy

Only the coder publisher exists in this pack. Do not provision or distribute merger/deploy keys merely because role names appear in the example. An eventual human-authorized extension must use a separate App, executor, permissions review, and explicit policy grants without bypassing branch or environment protections.

The optional [merge-when-green flow](POLICY.md#opt-in-merge) stays in the coder role. A human may deliberately add coder `merge` and authorize it, accepting that this expands the coder credential's permitted use. It does not borrow a merger grant or key. Leave that grant absent when strict coding/merging separation is required; human-only merge remains the default.

## Permissions by role

The coder App needs metadata read, contents write for authorized feature branches, and pull requests write for draft PRs. Issues write is optional for approved comment/label handlers; the publisher's installation token only requests contents and pull requests write. Keep repositories explicitly selected and retain human review and merge controls.
The coder App needs metadata read, contents write for authorized feature branches, and pull requests write for draft PRs. Issues write is optional for approved comment/label handlers. Normal publishing requests only contents and pull requests write; the opt-in merge flag also requests Checks read-only. Keep repositories explicitly selected and retain required human reviews and merge controls.

GitHub does not expose a separate draft-only or merge-only version of pull requests write. A coder token may technically call broader endpoints than the helper permits. Do not put the coder App on branch-rule bypass lists; restrict protected-branch updates and merges to authorized humans. Separate Apps reduce shared-key exposure but do not replace these controls.

Expand Down
Loading
Loading