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
2 changes: 2 additions & 0 deletions docs/METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ There is no closing marker or second document. An existing `<!-- agent-run:1 -->

The commit receives one `AI-Run` footer line; the PR body receives the tagged pair rather than another copy of that footer line. Evaluation comments are separate from both.

For interrupted publication, `agent-pr.mjs --resume <existing-head-sha>` uses the existing bot commit's model and run rather than the retrying harness environment. After policy, identity, exact-head, and required-check validation, it restores a missing tagged pair, leaves an identical pair unchanged, and refuses conflicting existing metadata. It never rewrites the commit or replaces an earlier session/model record. An absent committed `AI-Run` remains absent. See [POLICY.md](POLICY.md#resume-an-exact-published-head) for the resume-only gates and optional authorized merge.

## Validate and export locally

The default [trailer checker](../scripts/check-agent-trailers.mjs) still checks only `AI-Agent` and `AI-Model`. Opt in to requiring a valid, model-matching run trailer on agent-classified commits:
Expand Down
16 changes: 16 additions & 0 deletions docs/POLICY.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ Only after GitHub confirms the merge does it delete the remote feature branch. I

On failure, the published commit and PR can remain, and a timed-out flow may have marked a draft ready. Inspect the PR and both remote and local branches 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. See [ROLES.md](ROLES.md) for credential separation.

## Resume an exact published head

After an interrupted publication, use the existing commit's full lowercase SHA:

```bash
node scripts/agent-pr.mjs --resume <existing-head-sha>
```

This operation creates **no commit, push, or PR**. It requires a clean worktree on an unprotected feature branch, an existing commit with the configured App's verified bot author and committer, valid provenance trailers, and exactly one open, unmerged PR targeting origin's default branch. Local HEAD, the remote branch, and the PR head must all equal the supplied SHA. A missing PR or any drift is a refusal, not a reason to publish again. Committed protected paths and policy are checked as for normal publication; local, committed, and currently reviewed default-branch grants must agree.

Resume requests Checks read even without merging. Before recovering metadata it requires successful GitHub Actions `check-agent-trailers` on that exact SHA and every status check required by the base branch's protection and active rules, including configured App identities. Legacy commit statuses are accepted only for requirements without a pinned App. Missing, pending, failed, incomplete (more than 100 results), or unverifiable check results stop immediately; run resume again only after the same head is green. A legacy protection endpoint returning 404 is accepted when the base branch is confirmed unprotected, or when it is protected by rulesets with successfully fetched and validated nonempty required-status-check rules. A protected base with missing, empty, malformed, or unavailable required rules remains refused. API errors, including HTTP 422 when minting a Checks-scoped token, remain hard stops: an authorized human must resolve installation permissions, not an agent changing scopes or using human credentials.

The operation reads the original model and optional `AI-Run` from the existing commit, ignoring the retrying process's `AI_*` environment. It rejects `--message`, `--model`, and `--files`. A missing PR run block can be restored from that commit without replacing other text; an identical block is untouched and a conflicting existing block is refused. No absent metadata, counts, session, or task values are invented.

`--resume <existing-head-sha> --merge-when-green` additionally requires the same explicit human merge/cleanup authorization, separate approved credential context, and `merger.merge` gates described above. Resume revalidates exact heads, current coder grants, required checks, and worktree state during the merge wait and immediately before merging. It reuses the existing SHA-guarded merge and conservative cleanup flow with the original commit message and provenance. Without the merge flag, draft readiness, merging, and cleanup are not attempted.

## Limits

This is not a sandbox against a malicious human, compromised runner, or an agent that can replace its own trusted executor. Protect the default branch, loader, publisher, harness launch configuration, and credential storage. The policy checker does not create GitHub branch rules, scan all history for secrets, or independently prevent API calls made outside an approved executor. App permissions and GitHub protection rules remain necessary enforcement boundaries.
2 changes: 2 additions & 0 deletions docs/ROLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The optional [merge-when-green flow](POLICY.md#opt-in-merge) requires coder `com

The manifest specifies Metadata read, Checks read-only, and the repository scopes used for branch publication and review: Contents write, Issues write, and Pull requests write. If a broader agent workflow needs project or environment orchestration, add `repository_projects: write`, `organization_projects: write`, `actions: read`, `deployments: read`, `environments: read`, and `variables: read` only after the owner reviews the use case; these are not implicit requirements for every installation. Repository and organization projects are separate GitHub App permissions, and organization project access is not narrowed by the installation's selected repositories. Normal publishing requests only its core permissions; an approved orchestration token may request the reviewed subset, while the opt-in merge flag also requests Checks read-only. A human must accept permission changes on existing installations. Keep repositories explicitly selected and retain required human reviews and merge controls. Staged or selected `.github/workflows/**` paths are refused before token minting and published by humans; the coder App needs no Workflows permission.

The resume-only operation also requests Checks read-only so it can verify every required exact-head check before recovering metadata. It does not grant merge authority or switch credentials; `--merge-when-green` still requires the separately approved context and policy gates.

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.

Merger and deploy Apps, if ever approved, must have only the permissions their independently reviewed executor requires. Keep deployment credentials behind protected environments with human approval and approved branch restrictions. Do not add administration, secret-management, workflow-editing, or organization-member permissions to the coder App to work around a failed operation.
Expand Down
Loading
Loading