From 1bfbebdb17f6fad9ce752ec25d1c350759cce84d Mon Sep 17 00:00:00 2001 From: Utkarsh Sengar Date: Sat, 23 May 2026 18:10:21 -0700 Subject: [PATCH 1/2] ci: add PR explainer workflow (dogfoods @htmlbin/cli cloud + --upsert) A coding agent generates an HTML explainer of the diff on each push; `publish --upsert --metadata repo=...,pr=...` keeps the URL stable for the PR's lifetime. A sticky comment carries the URL and updates in place; the drop is deleted when the PR closes. Requires repo secrets HTMLBIN_TOKEN and ANTHROPIC_API_KEY. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/pr-explainer.yml | 152 +++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 .github/workflows/pr-explainer.yml diff --git a/.github/workflows/pr-explainer.yml b/.github/workflows/pr-explainer.yml new file mode 100644 index 0000000..724d7ab --- /dev/null +++ b/.github/workflows/pr-explainer.yml @@ -0,0 +1,152 @@ +# PR explainer for htmlbin-cli — dogfoods @htmlbin/cli. +# +# On every push to a PR, a coding agent reads the diff and writes a +# self-contained HTML explainer to ./preview.html. The CLI publishes it +# via the cloud backend with --upsert keyed on (repo, pr), so the URL is +# stable across the PR's lifetime. A sticky comment on the PR carries the +# URL; it updates in place on each push and is torn down when the PR closes. +# +# Required repo secrets (one-time): +# - HTMLBIN_TOKEN run `htmlbin login` locally, then add +# `cat ~/.config/htmlbin/token` as a repo secret +# - ANTHROPIC_API_KEY for Claude Code (the agent that writes the HTML) +# +# Note: pull_request triggers don't expose secrets to runs from forks. +# Forked-PR explainers won't generate until merged in or rerun from a +# branch in this repo. + +name: PR explainer +on: + pull_request: + types: [opened, synchronize, reopened, closed] + +permissions: + contents: read + pull-requests: write + +concurrency: + group: pr-explainer-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + publish: + if: github.event.action != 'closed' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # full history so the agent can diff against the base branch + fetch-depth: 0 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install Claude Code + run: npm install -g @anthropic-ai/claude-code + + - name: Generate explainer + run: | + claude -p "$(cat <<'EOF' + You are generating an HTML explainer for a code review. + + The working directory is a checkout of @htmlbin/cli (a TypeScript + command-line tool published to npm) with an open pull request. + The PR's base branch is "${{ github.event.pull_request.base.ref }}"; + the head is the current HEAD. + + 1. Run: git diff origin/${{ github.event.pull_request.base.ref }}...HEAD + 2. Read enough of the surrounding source to understand intent. + 3. Write a single self-contained HTML file at ./preview.html that + a reviewer can scan in under 30 seconds. Answer: + - What does this PR change? + - Why? (the user-facing or design motivation) + - What is the public surface impact — new flag, new verb, + new error code, behavior change, breaking change? + - What should the reviewer look at most carefully? + + Constraints on the HTML: + - Single file, inline CSS in