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
17 changes: 17 additions & 0 deletions .cursor/agents/ci-watcher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: ci-watcher
description: >-
Waits for the current PR's CI and returns only the failing jobs with the
tail of their logs. Use after every push instead of watching runs in the
main thread.
model: composer-2.5[fast=false]
readonly: true
---

# ci-watcher

1. Run `gh pr checks --watch --fail-fast > /dev/null 2>&1 || true`, then
`gh pr checks`.
2. For each failing check, run `gh run view RUN_ID --log-failed | tail -n 80`.
3. Report PASS, or for each failure: the job name, the run URL and those 80
lines. No analysis, no fixes, never full logs.
36 changes: 36 additions & 0 deletions .cursor/agents/ci-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: ci-workflow
description: >-
Makes GitHub Actions workflow and dependabot.yml edits that the parent has
fully specified (SHA pins, timeouts, permissions, env indirection,
concurrency, branch filters). Not for designing new workflows or release
flows.
model: composer-2.5[fast=false]
---

# ci-workflow

Rules (the owner rejects PRs that miss these):

- Pin every action to a full 40-character commit SHA with an exact
`# vX.Y.Z` comment. Look the SHA up, never guess:
`gh api repos/OWNER/REPO/git/ref/tags/vX.Y.Z --jq .object`; if its type
is "tag", dereference with
`gh api repos/OWNER/REPO/git/tags/SHA --jq .object.sha`.
Reuse SHAs already pinned in this repo's other workflows.
- `runs-on: ubuntu-24.04`. `timeout-minutes` on every job.
- Workflow-level `permissions: {}` or `contents: read`; write scopes only on
the job that needs them.
- `persist-credentials: false` on checkout unless the job pushes.
- No `${{ }}` inside `run:`. Pass values through `env:` and quote them
("$VAR"). For a list: `read -r -a args <<< "$VAR"`, then
`cmd "${args[@]}"`.
- No `pull_request_target` or `workflow_run`.
- Do not change triggers, job names or the job graph unless told to.

Steps: make the edits, run `actionlint` and
`zizmor --offline .github/workflows`, and fix until both are clean for the
files you touched.

Report: changes per file, each SHA with its tag, and the actionlint and
zizmor output.
23 changes: 23 additions & 0 deletions .cursor/agents/lint-fixer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: lint-fixer
description: >-
Fixes findings from scripts/lint.sh (actionlint, zizmor, shellcheck, shfmt,
ruff) that need no design change. Use whenever scripts/lint.sh fails.
model: composer-2.5[fast=false]
---

# lint-fixer

You fix lint findings in this repo and nothing else.

1. Run `scripts/lint.sh`.
2. Fix each finding at its file:line with the smallest change that follows
AGENTS.md.
3. Never add disable comments, noqa, ignore files or `|| true`. Never change
workflow triggers, permissions or the job graph to silence a finding. If a
finding needs a design change, stop and report it.
4. Rerun `scripts/lint.sh`. Stop when it passes or after 3 rounds.
5. Do not commit or push.

Report: each fix as file:line and rule, anything left and why, and the last
10 lines of `scripts/lint.sh` output.
1 change: 1 addition & 0 deletions .cursor/environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"install": "bash scripts/install-lint-tools.sh"}
6 changes: 6 additions & 0 deletions .cursor/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 1,
"hooks": {
"stop": [{ "command": ".cursor/hooks/lint-on-stop.sh", "loop_limit": 2 }]
}
}
18 changes: 18 additions & 0 deletions .cursor/hooks/lint-on-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Cursor stop hook: when scripts/lint.sh fails, send its output back to the
# agent as a follow-up. hooks.json caps the re-prompts with loop_limit.

set -euo pipefail

main() {
local output
if output="$(scripts/lint.sh 2>&1 </dev/null)"; then
echo '{}'
return
fi
python3 -c 'import json, sys
print(json.dumps({"followup_message": "scripts/lint.sh failed:\n" + sys.stdin.read()[-4000:]}))' \
<<<"${output}"
}

main "$@"
16 changes: 16 additions & 0 deletions .github/workflows/proxy_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# receive secrets for PRs from this repository, not from forks. Add PROXY_URL
# under Settings → Secrets and variables → Actions, and mark this workflow as
# a required status check under branch protection.
# - lint: scripts/lint.sh
# Runners are ubuntu-24.04. Do not switch these jobs to ubuntu-latest.

name: Proxy integration tests
Expand Down Expand Up @@ -80,3 +81,18 @@ jobs:
env:
PROXY_URL: ${{ secrets.PROXY_URL }}
run: python test_proxy_headers.py

lint:
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Install lint tools
run: bash scripts/install-lint-tools.sh

- name: Lint
run: scripts/lint.sh
87 changes: 87 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Agent instructions

Read `.cursorrules` too (git identity, PR footer rule).

## Checks (run before every push)

- `scripts/lint.sh` must pass. CI runs the same command. Tools come from
`scripts/install-lint-tools.sh`; never download linters yourself.
- Tests: `python test_header_security.py && python test_httpx_guard.py &&
python test_client_internals.py`.
- Prove it works: paste the command and its output for any behavior you
claim. CI green alone is not proof.

## Context and CI

- Never print full CI logs or whole large files.
- For the same edit in several places, write and run a small script
(sed, python) instead of many single edits, and show the script.
- Rewrite a file in one edit when you change most of it.

## Subagents

- After each push: use `ci-watcher` for CI; use `lint-fixer` when
`scripts/lint.sh` fails; use `ci-workflow` only for fully specified
workflow edits.
- Launch subagents only on composer-2.5 (standard speed) or grok-4.7.
No screenshots or computer use unless the task asks.

## Code standards (the owner rejects PRs that miss these)

- Follow PEP 8, the Google Python Style Guide, and the Google Shell Style
Guide (see `.cursorrules`). Run the repo linters and fix everything.
- Imports at the top of the module. No imports inside functions, methods
or class bodies. A guarded try/except ImportError at module top is fine
where versions truly differ.
- No classes or functions defined inside functions (no class factories)
unless there is a concrete reason you state in the PR body.
- Simple, direct code. No defensive scaffolding: no getattr/hasattr
fallback chains for names that exist in every supported version, no
runtime contract/signature checks, no debug/introspection helpers.
Check what the supported versions actually provide and import it
directly; tests and CI catch breakage.
- DRY with judgment: reuse existing helpers, no duplicate helpers, no
thin wrappers, no single-caller helpers extracted for neatness, no dead
code. Grep for unused functions before finishing.
- Match existing patterns and naming in the repo; smallest diff that does
the job. Do not reformat or restructure unrelated code.
- Logging: lazy args (`logger.info('x %s', y)`), never f-strings in log
calls. Retries: use the repo's retry library, not hand-rolled loops.
- Tests: cover the behavior change, reuse existing test layout and
fixtures, no giant harnesses when a focused test works.
- Use standard linters and tools instead of writing custom checkers, dev
servers or check runners.
- Shell scripts follow the Google Shell Style Guide (`main`, `set -euo
pipefail`, quoted vars, errors to stderr) and pass shellcheck + shfmt
`-i 2 -ci`.
- Workflows: actions pinned to full SHAs with version comments,
`ubuntu-24.04`, read-only default permissions with write only where
needed, `persist-credentials: false` unless pushing, timeouts, no
`${{ }}` inside `run:`, dependabot for github-actions; pass actionlint
and zizmor.
- CI: extend existing workflows before adding new ones. A new workflow
must justify itself in the PR body and stay small: no huge matrices
(lowest supported + current stable is usually enough), no pre-release
runtimes, no duplicated steps or duplicate scheduled jobs.
- One concern per PR, ideally under ~400 changed lines. Say what you would
split if it is bigger.
- Before finishing, re-read your full diff as a strict reviewer and fix
anything this list would flag. Report per-file line counts.

## Rules and what enforces them

| Rule | Enforced by |
| --- | --- |
| Workflows pass actionlint | `scripts/lint.sh`, CI lint job |
| Scoped permissions, no dangerous triggers | zizmor in `scripts/lint.sh` |
| No `${{ }}` in `run:` | zizmor in `scripts/lint.sh` |
| Shell scripts pass shellcheck and shfmt | `scripts/lint.sh` (style: review) |
| No real ProxyMesh proxy hostnames | hostname grep in `scripts/lint.sh` |
| Python passes ruff | `ruff check` in `scripts/lint.sh` |
| Imports at module top, no print | review (PLC0415, T201 planned) |
| Actions pinned to full SHAs | zizmor; SHA comment: review |
| Focused PRs under ~400 lines, no version bumps | review |

When a reviewer corrects the same mistake twice, add a check that fails on
it (lint rule, grep in `lint.sh`, or test) and add a row here. Docs-only
rules are for judgment calls nothing can check.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ Changelog = "https://github.com/proxymesh/python-proxy-headers/blob/main/CHANGEL
Issues = "https://github.com/proxymesh/python-proxy-headers/issues"
Documentation = "https://python-proxy-headers.readthedocs.io/en/latest/"
ProxyMesh = "https://proxymesh.com"

[tool.ruff.lint]
# Pre-0.16 default set; widen in follow-up PRs (PLC0415, T201).
select = ["E4", "E7", "E9", "F"]
3 changes: 1 addition & 2 deletions python_proxy_headers/autoscraper_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
"""

from typing import Dict, List, Optional, Any
from typing import Dict, List, Optional
from urllib.parse import urlparse

try:
Expand Down Expand Up @@ -209,7 +209,6 @@ def build(
Returns:
List of similar results
"""
from html import unescape
from autoscraper.utils import normalize, unique_hashable, unique_stack_list

if not wanted_list and not (wanted_dict and any(wanted_dict.values())):
Expand Down
3 changes: 2 additions & 1 deletion python_proxy_headers/urllib3_proxy_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http, sys
import http
import sys
from http.client import _read_headers
from urllib3.connection import HTTPSConnection
from urllib3.connectionpool import HTTPConnectionPool, HTTPSConnectionPool
Expand Down
69 changes: 69 additions & 0 deletions scripts/install-lint-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
# Install the pinned lint tools into ~/.local/bin (linux x86_64).
# CI and .cursor/environment.json both run this script.

set -euo pipefail

readonly BIN_DIR="${HOME}/.local/bin"
readonly GH="https://github.com"

err() {
echo "$*" >&2
}

# Download a URL to a file and check its sha256.
fetch() {
local url="$1"
local sha="$2"
local dest="$3"
curl -fsSL -o "${dest}" "${url}"
echo "${sha} ${dest}" | sha256sum -c --quiet - || {
err "checksum mismatch: ${url}"
exit 1
}
}

install_actionlint() {
local version="1.7.12"
local sha="8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8"
fetch \
"${GH}/rhysd/actionlint/releases/download/v${version}/actionlint_${version}_linux_amd64.tar.gz" \
"${sha}" "${TMP}/actionlint.tar.gz"
tar -xzf "${TMP}/actionlint.tar.gz" -C "${BIN_DIR}" actionlint
}

install_shellcheck() {
local version="0.11.0"
local sha="b7af85e41cc99489dcc21d66c6d5f3685138f06d34651e6d34b42ec6d54fe6f6"
fetch \
"${GH}/koalaman/shellcheck/releases/download/v${version}/shellcheck-v${version}.linux.x86_64.tar.gz" \
"${sha}" "${TMP}/shellcheck.tar.gz"
tar -xzf "${TMP}/shellcheck.tar.gz" -C "${TMP}"
install -m 755 "${TMP}/shellcheck-v${version}/shellcheck" "${BIN_DIR}"
}

install_shfmt() {
local version="3.14.1"
local sha="76e77641faa025814b77f153b29796b8e6fa2fca03e0c76a691608b86c7ea7bf"
fetch \
"${GH}/mvdan/sh/releases/download/v${version}/shfmt_v${version}_linux_amd64" \
"${sha}" "${TMP}/shfmt"
install -m 755 "${TMP}/shfmt" "${BIN_DIR}/shfmt"
}

install_python_tools() {
python3 -m pip install --user --quiet --break-system-packages \
"ruff==0.17.5" "zizmor==1.32.0"
}

main() {
TMP="$(mktemp -d)"
trap 'rm -rf "${TMP}"' EXIT
mkdir -p "${BIN_DIR}"
install_actionlint
install_shellcheck
install_shfmt
install_python_tools
}

main "$@"
62 changes: 62 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
# Run every repo lint check. CI, the stop hook and agents all run this.
# Install the tools first with scripts/install-lint-tools.sh.

set -euo pipefail

failed=()

err() {
echo "$*" >&2
}

# Run a check and remember its name if it fails.
check() {
local name="$1"
shift
"$@" || failed+=("${name}")
}

# Fail on real ProxyMesh proxy hosts; docs. and www. are allowed.
check_hostnames() {
! git grep --untracked -nIoE '[a-z0-9-]+\.proxymesh\.com' |
grep -vE ':(docs|www)\.proxymesh\.com$'
}

main() {
export PATH="${HOME}/.local/bin:${PATH}"
cd "$(git rev-parse --show-toplevel)"
local -a sh_files
mapfile -t sh_files < <(git ls-files -co --exclude-standard '*.sh')

check actionlint actionlint
# Skip legacy release workflows; zizmor only on workflows this branch changes.
local -a wf=()
local path base="origin/main"
for path in .github/workflows/*; do
if [[ "$path" == .github/workflows/publish.yml ]] ||
[[ "$path" == .github/workflows/github_release_on_release_branch_merge.yml ]]; then
continue
fi
if git rev-parse --verify --quiet "${base}" >/dev/null &&
git cat-file -e "${base}:${path}" 2>/dev/null &&
git diff --quiet "${base}" -- "$path"; then
continue
fi
wf+=("$path")
done
if ((${#wf[@]} > 0)); then
check zizmor zizmor --quiet --offline "${wf[@]}"
fi
check shellcheck shellcheck "${sh_files[@]}"
check shfmt shfmt -d -i 2 -ci "${sh_files[@]}"
check ruff ruff check
check hostnames check_hostnames

if ((${#failed[@]} > 0)); then
err "lint failed: ${failed[*]}"
exit 1
fi
}

main "$@"
1 change: 0 additions & 1 deletion test_proxy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

import os
import sys
import importlib
import traceback
from abc import ABC, abstractmethod
from dataclasses import dataclass
Expand Down