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
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ 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
```

## Optional run metadata

- Harnesses SHOULD export the known `AI_PROVIDER`, `AI_MODEL`, `AI_MODEL_VERSION`, `AI_EFFORT`, `AI_CONTEXT_USED`, `AI_CONTEXT_MAX`, `AI_CONTEXT_OUT`, `AI_SESSION`, and `AI_TASK` values before invoking `agent-pr.mjs`. Never invent missing values or infer counts, effort, session, or task identifiers.
- Follow `docs/METRICS.md`: the helper emits a single optional compact `AI-Run` trailer and tagged PR body pair when metadata is supplied. `--model` overrides `AI_MODEL`; absent environment metadata leaves the two required trailers unchanged. No prompts, traces, credentials, extra `AI-X-*` trailers, or second YAML document belong in git.
- Humans evaluate through separate `AI-Eval` PR comments, not by editing trailers. Agents must not generate evaluations, quality scores, or analytics-service integrations.

## Day-1 build targets

Implement what `docs/DAY1_SCOPE.md` lists. Prefer small, tested files.
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ See [HARNESSES](docs/HARNESSES.md) for integration details. On a dedicated WSL/H

## Use in another repo

Follow [ONBOARDING](docs/ONBOARDING.md) for the complete file list and [adopt.md](docs/adopt.md) for distribution options. Copy the [consumer workflow](examples/consumer-repo/.github/workflows/check-agent-trailers.yml) with a pinned public Action, or vendor the [composite Action](.github/actions/check-agent-trailers/action.yml) with both checker scripts. No private-package infrastructure or App credentials are required for the read-only trailer check itself.
Follow [ONBOARDING](docs/ONBOARDING.md) for the complete file list and [adopt.md](docs/adopt.md) for distribution options. Copy the [consumer workflow](examples/consumer-repo/.github/workflows/check-agent-trailers.yml) with a pinned public Action, or vendor the [composite Action](.github/actions/check-agent-trailers/action.yml) with both checker scripts and their [shared parser](scripts/parse-agent-run.mjs). No private-package infrastructure or App credentials are required for the read-only trailer check itself.

The manifest is a static template, not a hosted registration button. Its placeholder callback URLs need an owner-controlled receiver for GitHub's manifest flow; onboarding also documents the manual registration path. No hosted callback or control plane is provided.

Expand All @@ -75,6 +75,10 @@ The check inspects messages containing `AI-Agent:` and GitHub noreply bot author

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.

## With gh-aw

The [issue clarifier source](.github/workflows-src/issue-clarifier.md) illustrates `permissions: read-all` and a comment-only safe output. Approved output handlers must enforce the repository policy too. Keep Markdown sources uncompiled unless `gh aw` is already installed; no generated lockfile or agent runtime is required to use the identity contract.
Expand Down
106 changes: 106 additions & 0 deletions docs/METRICS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# 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.

## Schema 1

```text
AI-Run: <schema>|<provider>|<model>@<version>|<effort>|<in>/<max>|<out>|<session>|<task>
```

Example footer:

```text
AI-Agent: hermes-coder
AI-Model: claude-sonnet-4.5
AI-Run: 1|anthropic|claude-sonnet-4.5@20250901|h|18234/200000|2510|ses_01K8|feat-auth
```

| Column | Rule |
| --- | --- |
| 1: schema | Exactly `1` |
| 2: provider | `anthropic`, `openai`, `github-copilot`, `local`, or `other` |
| 3: model@version | Model must match `AI-Model`; version is `[A-Za-z0-9._-]+` or `unknown` |
| 4: effort | `l`, `m`, `h`, or `x` for low, medium, high, or max |
| 5: in/max | Two nonnegative decimal integer counts, each independently allowed to be `-` |
| 6: out | Nonnegative decimal integer count or `-` |
| 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`.

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.

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.

## Harness environment

Export only values actually reported by the harness before invoking [agent-pr.mjs](../scripts/agent-pr.mjs). The helper does not read `.env`, infer a provider from a model, estimate token counts, or generate session/task IDs.

| 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_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` | `-` |
| `AI_CONTEXT_MAX` | `max` | `-` |
| `AI_CONTEXT_OUT` | `out` | `-` |
| `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.

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 `-`.

## PR body

When run metadata is present, the publisher upserts exactly this two-line pair:

```text
<!-- agent-run:1 -->
`1|anthropic|claude-sonnet-4.5@20250901|h|18234/200000|2510|ses_01K8|feat-auth`
```

There is no closing marker or second document. An existing `<!-- agent-run:1 -->` pair is replaced; duplicates are collapsed to one pair. Other PR body text is retained. For an existing PR, the helper reads the current body and verifies the branch and head SHA before updating it. A new draft PR receives the pair at creation. When no run metadata is supplied, the helper does not modify existing PR metadata.

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.

## 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:

```bash
node scripts/check-agent-trailers.mjs --require-run --message-file path/to/message.txt
node scripts/check-agent-trailers.mjs --require --require-run --message-file path/to/message.txt
```

`--require-run` alone does not classify an unmarked human commit as an agent commit. Combine it with `--require` to check every message. The default PR workflow and its permissions are unchanged.

The [message parser](../scripts/parse-agent-run.mjs) and [history exporter](../scripts/export-agent-metrics.mjs) print JSONL to standard output, with one object per commit containing run metadata:

```bash
node scripts/parse-agent-run.mjs --message-file path/to/message.txt
node scripts/export-agent-metrics.mjs
node scripts/export-agent-metrics.mjs --ref main..HEAD
```

```json
{"sha":"0123456789abcdef0123456789abcdef01234567","agent":"hermes-coder","model":"claude-sonnet-4.5","schema":1,"provider":"anthropic","model_version":"20250901","effort":"h","context_used":18234,"context_max":200000,"context_out":2510,"session":"ses_01K8","task":"feat-auth"}
```

The message parser accepts `--message TEXT` instead of `--message-file`, plus an optional full `--sha`; without it, `sha` is `null`. The history exporter reads only local Git history, defaults to `HEAD`, and emits oldest first. Neither fetches from GitHub or exports commit bodies, prompts, traces, unknown fields, or evaluations.

JSON uses `null` for `-` sentinels, integer numbers for counts, and a string for `model_version`, including `unknown`. Integers beyond JavaScript's safe range remain decimal strings instead of being rounded. Commits without metadata are skipped. A malformed record fails export without partial output. Exit codes are `0` for success or no records, `1` for metadata/history errors, and `2` for usage or message-file input errors. Both commands support `--help`.

When vendoring the checker or publisher, include `scripts/parse-agent-run.mjs` as well as their existing dependencies. The read-only exporter is optional. See [adopt.md](adopt.md).

## Human evaluation comments

A human may leave this separate PR comment:

```text
AI-Eval: 1|accept|3|n
```

This documents a human comment format only. `accept` is the human's decision; the remaining values are not interpreted or assigned a scoring scale by v0.2.0. The publisher must not generate `AI-Eval`, post evaluation comments, or add an evaluation trailer. Humans evaluate via comments, not by rewriting commit trailers. The parser and exporter do not process these comments or calculate quality scores.
5 changes: 4 additions & 1 deletion docs/ONBOARDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ scripts/agent-pr.mjs
scripts/load-agent-policy.mjs
scripts/check-agent-trailers.mjs
scripts/check-pr-agent-trailers.mjs
scripts/parse-agent-run.mjs
examples/agent-policy.yml
.github/actions/check-agent-trailers/action.yml
.github/workflows/check-agent-trailers.yml
```

Use Node 20+, Git, and `gh` for publication. Adapt the workspace name and test command in the copied rules. Follow [HARNESSES.md](HARNESSES.md) for the small harness-specific pointers, and [adopt.md](adopt.md) for the pinned public-Action alternative and vendoring details. No private-package infrastructure or runtime dependency installation is needed.

The shared parser is required by the checker and publisher. Optional run metadata and the local JSONL exporter are documented in [METRICS.md](METRICS.md); no `AI_*` run variables are required for ordinary publication.

A human must review [the policy example](../examples/agent-policy.yml), install it as root `agent-policy.yml`, and publish it on the default branch through the existing human review process. Include that reviewed version in the feature branch too. Keep merger and deploy allow-lists empty. The publisher requires coder `commit_branch` and `open_pr`, checks the default-branch policy, and refuses root-policy edits; there is no example fallback. See [POLICY.md](POLICY.md) and [ROLES.md](ROLES.md). Copy their guidance with the skills when adopting the pack.

For the local Action, land the Action and both checker scripts on the target branch before enabling the workflow, because it executes the base revision's trusted checker. A human bootstraps and publishes `.github/workflows/**` changes: the helper refuses staged or selected workflow paths before token minting, and the coder App intentionally has no Workflows permission. Keep human review on changes to the workflow, instructions, and publisher.
For the local Action, land the Action, both checker scripts, and the shared parser on the target branch before enabling the workflow, because it executes the base revision's trusted checker. A human bootstraps and publishes `.github/workflows/**` changes: the helper refuses staged or selected workflow paths before token minting, and the coder App intentionally has no Workflows permission. Keep human review on changes to the workflow, instructions, and publisher.

## 3. Protect the branch and publish

Expand Down
9 changes: 6 additions & 3 deletions docs/adopt.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ Use this option when the consumer cannot reference the public Action or needs to
.github/actions/check-agent-trailers/action.yml
scripts/check-agent-trailers.mjs
scripts/check-pr-agent-trailers.mjs
scripts/parse-agent-run.mjs
```

The source files are the [composite Action](../.github/actions/check-agent-trailers/action.yml), [message checker](../scripts/check-agent-trailers.mjs), and [PR runner](../scripts/check-pr-agent-trailers.mjs). Retain the pack's [MIT notice](../LICENSE) with the vendored files without replacing the consumer's own license.
The source files are the [composite Action](../.github/actions/check-agent-trailers/action.yml), [message checker](../scripts/check-agent-trailers.mjs), [PR runner](../scripts/check-pr-agent-trailers.mjs), and [shared parser](../scripts/parse-agent-run.mjs). Retain the pack's [MIT notice](../LICENSE) with the vendored files without replacing the consumer's own license.

**Copying only the Action metadata is not sufficient.** Its command expects both scripts at the relative paths above. Copying instruction files or a workflow does not make a local `uses: ./.github/actions/check-agent-trailers` reference point back to this pack.
**Copying only the Action metadata is not sufficient.** Its command needs both checker scripts and their shared parser at the relative paths above. Copying instruction files or a workflow does not make a local `uses: ./.github/actions/check-agent-trailers` reference point back to this pack.

For this option, copy the pack's [local workflow](../.github/workflows/check-agent-trailers.yml), not the remotely pinned consumer example. The local workflow fetches full PR history, checks out the trusted base revision, and then runs:

Expand All @@ -39,7 +40,7 @@ For this option, copy the pack's [local workflow](../.github/workflows/check-age
head-sha: ${{ github.event.pull_request.head.sha }}
```

Land the Action and both scripts on the target branch in a reviewed bootstrap change **before enabling the local workflow**. Otherwise its first run cannot find the checker at the base revision. Keep the trusted-base checkout step when adopting the local workflow; checker updates take effect after they reach that branch.
Land the Action, both checker scripts, and the shared parser on the target branch in a reviewed bootstrap change **before enabling the local workflow**. Otherwise its first run cannot find the checker at the base revision. Keep the trusted-base checkout step when adopting the local workflow; checker updates take effect after they reach that branch.

For local validation and future updates, also copy the [message-checker tests](../tests/check-agent-trailers.test.mjs) and [PR-runner tests](../tests/check-pr-agent-trailers.test.mjs) into `tests/`. With Node 20+ and Git available, run from the consumer root:

Expand All @@ -50,6 +51,8 @@ node --test tests/*.test.mjs

Update the Action, scripts, and tests together from a reviewed revision. Neither adoption option needs `npm install`.

Optional v0.2.0 run metadata is described in [METRICS.md](METRICS.md). Copy [export-agent-metrics.mjs](../scripts/export-agent-metrics.mjs) for local JSONL export if needed. The shared parser remains required by the checker even when run metadata is not enabled; the default trailer policy is unchanged.

## Choose the policy

By default, every PR commit is inspected, but required trailers are enforced only when its message contains `AI-Agent:` or its author has a GitHub noreply bot address. Human privacy addresses alone do not trigger the check. See the [trailer specification](commit-trailers.md) for exact parsing and bot-address rules.
Expand Down
Loading
Loading