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
288 changes: 288 additions & 0 deletions .github/workflows/judge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
# The Morphogen judge for GitHub Actions, as a reusable workflow, reading the catalog (`spec.morphogen` on the
# entities of `catalog-info.yaml`). A caller runs it from its own `pull_request_target` workflow, so the definition
# that runs is the base's: a pull request cannot edit what judges it. Judgement is the package's own
# (`morphogen pr`, which hands the judge a request, morphogen/request.py); this file only fetches, supplies and posts.
#
# judge fetches base and head as git objects (the candidate is never checked out here; the judge makes its own
# worktrees), installs the judge at `judge-ref` from hash-locked wheels, clones the operator's private
# material (morphogen.local.yaml and the held-out answers it names) outside the repository, and runs
# `morphogen pr`: rules from the base commit, a candidate that changes a catalog file refused, every candidate
# command in a container with no network that sees only the candidate's tree (never `sandbox: none`), the
# answers given only to the base's scorer. Its token can only read.
# post signs the verdict (Sigstore), posts `morphogen/verdict` on the head commit and keeps the verdict and the
# evidence records as artifacts. A judge that failed is posted as a stop, never a pass.
name: morphogen-judge
on:
workflow_call:
inputs:
judge-ref:
description: The Morphogen commit to judge with. Must equal the commit in the caller's `uses:` line.
required: true
type: string
cases-repo:
description: owner/name of the repository holding the operator's private material (MORPHOGEN_CASES_TOKEN must read it). Empty means none.
required: false
type: string
default: ""
cases-branch:
required: false
type: string
default: main
cases-dir:
description: The directory in cases-repo holding morphogen.local.yaml; relative paths in that file are read from there.
required: false
type: string
default: "."
sandbox:
description: Where candidates run, `docker` or `podman` (both on GitHub's Ubuntu runners). `none` is refused.
required: false
type: string
default: docker
protected:
description: Globs (space or newline separated) no pull request may change, beyond the catalog files, which the judge always refuses.
required: false
type: string
default: ".github/**"
verdict-poster:
description: "Who posts `morphogen/verdict`. `actions`: the workflow token (anyone with write access can post the same status). `app`: a GitHub App only the judge holds the key of; require the status from that app in the ruleset."
required: false
type: string
default: actions
signing:
description: "`keyless`: the workflow's OIDC identity, logged in the public Sigstore transparency log. `key`: a cosign key pair held in the environment."
required: false
type: string
default: keyless
timeout-minutes:
description: The judge job's limit (GitHub-hosted runners stop at 360).
required: false
type: number
default: 360
# Callers pass these with `secrets: inherit` (on the morphogen-judge environment or the repository).
secrets:
MORPHOGEN_CASES_TOKEN:
description: Reads cases-repo. Needed unless cases-repo is this repository.
required: false
MORPHOGEN_COSIGN_KEY:
required: false
MORPHOGEN_COSIGN_PASSWORD:
required: false
MORPHOGEN_APP_CLIENT_ID:
description: "The judge's GitHub App client ID (with verdict-poster app)."
required: false
MORPHOGEN_APP_KEY:
description: "The judge's GitHub App private key (with verdict-poster app)."
required: false

permissions: {}

concurrency:
group: morphogen-judge-${{ github.repository }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

env:
PR: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_REF: ${{ github.event.pull_request.base.ref }}

jobs:
judge:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-24.04
timeout-minutes: ${{ inputs.timeout-minutes }}
environment: morphogen-judge
permissions:
contents: read
outputs:
verdict: ${{ steps.judge.outputs.verdict }}
steps:
- name: Check the inputs
env:
SANDBOX: ${{ inputs.sandbox }}
POSTER: ${{ inputs.verdict-poster }}
SIGNING: ${{ inputs.signing }}
CASES_DIR: ${{ inputs.cases-dir }}
run: |
case "$SANDBOX" in docker|podman) ;; *) echo "::error::sandbox must be docker or podman: without a container a candidate can read the held-out answers"; exit 1;; esac
case "$POSTER" in app|actions) ;; *) echo "::error::verdict-poster must be app or actions"; exit 1;; esac
case "$SIGNING" in keyless|key) ;; *) echo "::error::signing must be keyless or key"; exit 1;; esac
case "/$CASES_DIR/" in */../*|//*) echo "::error::cases-dir must be a relative path inside cases-repo"; exit 1;; esac
- name: Get the judge
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: openreplicant/morphogen
ref: ${{ inputs.judge-ref }}
path: .judge
persist-credentials: false
- name: Install the judge (a venv; hash-locked wheels only)
run: |
python3 -m venv "$RUNNER_TEMP/mg"
"$RUNNER_TEMP/mg/bin/pip" install --quiet --only-binary=:all: --require-hashes -r .judge/requirements.lock
- name: Fetch base and head as git objects (nothing is checked out; the judge makes its own worktrees)
env:
GIT_TOKEN: ${{ github.token }}
run: |
set -eu
auth="http.extraHeader=Authorization: Basic $(printf 'x-access-token:%s' "$GIT_TOKEN" | base64 -w0)"
git init -q repo
git -C repo -c "$auth" -c fetch.fsckObjects=true fetch -q --no-tags "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" \
"+refs/heads/$BASE_REF:refs/morphogen/base" "+refs/pull/$PR/head:refs/morphogen/head"
got=$(git -C repo rev-parse refs/morphogen/head)
if [ "$got" != "$HEAD_SHA" ]; then
echo "::error::the pull request moved ($got, not $HEAD_SHA); the run for its new head judges it"; exit 1
fi
echo "base $(git -C repo rev-parse refs/morphogen/base), head $got"
- name: Fetch the operator's private material, outside the repository
if: inputs.cases-repo != ''
env:
CASES_TOKEN: ${{ secrets.MORPHOGEN_CASES_TOKEN }}
REPO_TOKEN: ${{ github.token }}
CASES_REPO: ${{ inputs.cases-repo }}
CASES_BRANCH: ${{ inputs.cases-branch }}
run: |
set -eu
# The workflow's own token only ever reaches this repository; another one needs the case token.
if [ -z "$CASES_TOKEN" ]; then
if [ "$CASES_REPO" != "$GITHUB_REPOSITORY" ]; then
echo "::error::MORPHOGEN_CASES_TOKEN is not available to this job; the caller must pass secrets (secrets: inherit)"; exit 1
fi
CASES_TOKEN="$REPO_TOKEN"
fi
git -c "http.extraHeader=Authorization: Basic $(printf 'x-access-token:%s' "$CASES_TOKEN" | base64 -w0)" \
clone -q --depth 1 --single-branch --branch "$CASES_BRANCH" "$GITHUB_SERVER_URL/$CASES_REPO.git" "$RUNNER_TEMP/cases"
rm -rf "$RUNNER_TEMP/cases/.git"
- id: judge
name: Judge (morphogen pr; the rules from the base commit)
env:
PYTHONPATH: ${{ github.workspace }}/.judge
PR_BODY: ${{ github.event.pull_request.body }}
SANDBOX: ${{ inputs.sandbox }}
PROTECTED: ${{ inputs.protected }}
CASES_DIR: ${{ inputs.cases-dir }}
JUDGE_REF: ${{ inputs.judge-ref }}
run: |
set +e -u # a fail is a verdict to keep and post, not a failed step (GitHub runs bash -e)
mkdir -p "$RUNNER_TEMP/out"
set -- --base refs/morphogen/base --head "$HEAD_SHA" --sandbox "$SANDBOX" --pull --body-env PR_BODY \
--out "$RUNNER_TEMP/out/verdict.json" --label "repository=$GITHUB_REPOSITORY" --label "pull_request=$PR" \
--label "run=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" --label "judge=$JUDGE_REF"
local_file="$RUNNER_TEMP/cases/$CASES_DIR/morphogen.local.yaml"
if [ -f "$local_file" ]; then set -- "$@" --local "$local_file"; fi
set -f # the globs are the judge's to match, not the shell's
for g in $PROTECTED; do set -- "$@" --protect "$g"; done
set +f
cd repo
# -P: nothing from the working directory shadows the judge's modules.
"$RUNNER_TEMP/mg/bin/python" -P -m morphogen pr "$@"
code=$?
"$RUNNER_TEMP/mg/bin/python" -P -m morphogen evidence --limit 100000 > "$RUNNER_TEMP/out/evidence.json" || true
"$RUNNER_TEMP/mg/bin/python" -P -m morphogen evidence --verify > "$RUNNER_TEMP/out/evidence-verify.json" || true
echo "verdict=$(jq -r .verdict "$RUNNER_TEMP/out/verdict.json")" >> "$GITHUB_OUTPUT"
echo "exit $code"
[ "$code" -le 1 ] # 0 pass, 1 fail: both are verdicts; 2 is a stop
- name: Remove the private material
if: always()
run: rm -rf "$RUNNER_TEMP/cases"
- if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: verdict
path: ${{ runner.temp }}/out
if-no-files-found: ignore
retention-days: 90

post:
# Sign and post whatever the judge said; when the judge itself failed, a `stop`, never a pass, and never silence.
needs: judge
if: always() && github.event_name == 'pull_request_target'
runs-on: ubuntu-24.04
environment: morphogen-judge
permissions:
statuses: write
id-token: write # keyless signing: the verdict is signed by this workflow's identity
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
continue-on-error: true
with:
name: verdict
path: art
- name: Read the verdict
env:
JUDGE_RESULT: ${{ needs.judge.result }}
run: |
set -eu
f=art/verdict.json
if [ "$JUDGE_RESULT" != success ] || [ ! -f "$f" ]; then
why=$(jq -r '.summary // empty' "$f" 2>/dev/null || true)
jq -n --arg s "stop: the judge failed (judge=$JUDGE_RESULT)${why:+; $why}" --arg h "$HEAD_SHA" \
'{morphogen:"pr-verdict/v1", verdict:"stop", judged:false, head:$h, summary:$s}' > verdict.json
else
cp "$f" verdict.json
v=$(jq -r .verdict verdict.json); h=$(jq -r '.head // empty' verdict.json)
case "$v" in pass|fail|not-judged|stop) ;; *) echo "::error::unknown verdict $v"; exit 1;; esac
if [ -n "$h" ] && [ "$h" != "$HEAD_SHA" ]; then echo "::error::the verdict is for $h, not $HEAD_SHA"; exit 1; fi
fi
cp art/evidence.json evidence.json 2>/dev/null || echo '[]' > evidence.json
- uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
with:
cosign-release: v3.1.4
- name: Sign
env:
SIGNING: ${{ inputs.signing }}
COSIGN_KEY: ${{ secrets.MORPHOGEN_COSIGN_KEY }}
COSIGN_PASSWORD: ${{ secrets.MORPHOGEN_COSIGN_PASSWORD }}
run: |
if [ "$SIGNING" = keyless ]; then
cosign sign-blob --yes --bundle verdict.sigstore.json verdict.json
else
umask 077 && printf '%s' "$COSIGN_KEY" > "$RUNNER_TEMP/k"
echo '{"mediaType":"application/vnd.dev.sigstore.signingconfig.v0.2+json","rekorTlogConfig":{},"tsaConfig":{}}' > "$RUNNER_TEMP/sc.json"
cosign sign-blob --yes --key "$RUNNER_TEMP/k" --signing-config "$RUNNER_TEMP/sc.json" --bundle verdict.sigstore.json verdict.json
rm -f "$RUNNER_TEMP/k"
fi
- id: app
name: Get the judge's GitHub App token (statuses only)
if: inputs.verdict-poster == 'app'
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.MORPHOGEN_APP_CLIENT_ID }}
private-key: ${{ secrets.MORPHOGEN_APP_KEY }}
permission-statuses: write
- name: Post the verdict
env:
GH_TOKEN: ${{ inputs.verdict-poster == 'app' && steps.app.outputs.token || github.token }}
run: |
set -eu
v=$(jq -r .verdict verdict.json)
case "$v" in pass|not-judged) state=success;; *) state=failure;; esac
body=$(jq --arg st "$state" --arg u "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
'{state:$st, context:"morphogen/verdict", description:(.summary // .verdict)[0:138], target_url:$u}' verdict.json)
curl -fsS -o /dev/null -X POST -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
-d "$body" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/statuses/$HEAD_SHA"
echo "posted morphogen/verdict=$state ($v)"
{
echo "## Morphogen: $(jq -r '.summary // .verdict' verdict.json)"
echo
jq -r '"- base `\(.base // "?")`, head `\(.head // "?")`, judged `\(.candidate // "?")`\(if .merged then " (head merged onto base)" else "" end)",
"- gate: \(.gate.decision // "none")",
(.reasons // [] | .[] | "- \(.)")' verdict.json
} >> "$GITHUB_STEP_SUMMARY"
- name: Post a stop if posting the verdict failed
if: failure()
env:
GH_TOKEN: ${{ steps.app.outputs.token || github.token }}
run: |
body=$(jq -n --arg u "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
'{state:"failure", context:"morphogen/verdict", description:"stop: the judge could not sign or post its verdict", target_url:$u}')
curl -fsS -o /dev/null -X POST -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
-d "$body" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/statuses/$HEAD_SHA"
- if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: verdict-signed
path: |
verdict.json
verdict.sigstore.json
evidence.json
if-no-files-found: ignore
retention-days: 90
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ docs/restart/LESSONS.md.
`otel`), `project.py` (the cell format: `spec.morphogen` on the catalog's entities, default deny),
`backstage.py` (the catalog: `catalog-info.yaml` and its Location targets, read into cells, interfaces and settings),
`status.py` (where a project stands and the next step),
`documents.py` (the project's settings, from the System's `spec.morphogen`, and the target spec a cell compiles to), `request.py` (one document in, one verdict out), `intake.py` (the judge held by another user: a candidate arrives as a git bundle), `cli.py`, `mcp_server.py`, `ui.py` and `ui.html` (the read-only web UI).
`documents.py` (the project's settings, from the System's `spec.morphogen`, and the target spec a cell compiles to), `request.py` (one document in, one verdict out), `pullrequest.py` (`morphogen pr`: a pull request as the GitHub judge, `.github/workflows/judge.yml`, hands it to the judge as a request), `intake.py` (the judge held by another user: a candidate arrives as a git bundle), `cli.py`, `mcp_server.py`, `ui.py` and `ui.html` (the read-only web UI).
- `.claude-plugin/`, `skills/`, `agents/`: the Claude Code plugin around the MCP server. Skills (the kit):
`morphogen` (improve a cell), `map` (take a system apart into Backstage entity files and draft cells),
`catalog` and `research` (options for a role, as `lifecycle: candidate` Components). `schemas/morphogen-spec.v1.json`
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ uv run morphogen measure cell:classify
uv run morphogen judge cell:classify my-branch
uv run morphogen change my-branch # a change that claims no improvement: its cells' tests
uv run morphogen request /outside/request.yaml # one document: what to judge, and the operator's settings
uv run morphogen pr --base main --head HEAD --sandbox podman --local /outside/morphogen.local.yaml --out v.json
# a pull request, as the GitHub judge runs it
uv run morphogen tune cell:classify # the selector chooses optimizers
uv run morphogen optimizers # the catalog
uv run morphogen evidence --verify
Expand Down Expand Up @@ -429,6 +431,46 @@ that commit the base and be judged by them.
Rootless Podman keeps images and containers per user, so the judge needs the sandbox image, any
service images and its own model gateway in its own store.

## On GitHub: the judge as a reusable workflow

`.github/workflows/judge.yml` judges every pull request into your main branch by the catalog on main. Your repository
needs only `catalog-info.yaml`; the operator's private material (a `morphogen.local.yaml` naming the held-out answers,
inputs, env file and services, with the directories it names) lives in a private repository the workflow clones
outside your checkout. Call it from a `pull_request_target` workflow, so the definition that runs is main's:

```yaml
name: morphogen
on:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened, edited]
permissions: {}
jobs:
judge:
uses: OpenReplicant/Morphogen/.github/workflows/judge.yml@COMMIT # pin by commit
permissions: {contents: read, statuses: write, id-token: write}
secrets: inherit # MORPHOGEN_CASES_TOKEN, and the App's keys with verdict-poster: app
with:
judge-ref: COMMIT # the same commit
cases-repo: you/your-judge-material # holds DIR/morphogen.local.yaml and what it names
cases-dir: your-project # paths in that file are relative to it
protected: ".github/** .morphogen/**" # beyond the catalog files, which are always refused
sandbox: docker # or podman; never none
verdict-poster: app # or actions
```

The `judge` job holds only a read token. It fetches main and the pull request's head as git objects (nothing of the
candidate is checked out by the workflow), installs the judge at `judge-ref` from hash-locked wheels
(`requirements.lock`, exported from `uv.lock`), clones the private material, and runs `morphogen pr`, which hands the
judge a request (above) and so keeps every rule it keeps: the rules from main as it is now (a branch behind main is
judged merged onto it), a candidate that changes a catalog file or `morphogen.local.yaml` refused, every candidate
command in a container with no network that sees only the candidate's tree, the answers given only to main's scorer.
A pull request that touches no file any cell may change, and no rule file, is a pass (not judged); one that touches a
`protected` path is refused. Name the cell to judge with a line `morphogen-target: cell:NAME` in the pull request's
description; without one, the change is judged as one that claims no improvement (`morphogen change`). The `post`
job signs the verdict (Sigstore, keyless by default), posts `morphogen/verdict` on the head commit and keeps the
verdict and the run's evidence records as artifacts; a judge that fails is posted as a stop, never a pass.

## What the judge guarantees

- **The rules are the base's.** The catalog files and everything a cell's `change` does not name come
Expand Down
Loading