diff --git a/.github/workflows/dupehound.yml b/.github/workflows/dupehound.yml new file mode 100644 index 00000000..5c177709 --- /dev/null +++ b/.github/workflows/dupehound.yml @@ -0,0 +1,58 @@ +name: dupehound + +on: + pull_request: + paths: + - 'src/**' + - 'tests/**' + push: + branches: [main] + paths: + - 'src/**' + - 'tests/**' + +permissions: + contents: read + +jobs: + check: + name: Block new duplicates + runs-on: ubuntu-latest + timeout-minutes: 5 + continue-on-error: true + steps: + - name: Checkout + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + with: + fetch-depth: 0 + - name: Install dupehound + run: | + curl -sL https://github.com/Rafaelpta/dupehound/releases/latest/download/dupehound-x86_64-unknown-linux-gnu.tar.gz | tar xz + sudo mv dupehound /usr/local/bin/ + - name: Block new duplicates vs base + env: + PR_BASE: ${{ github.event.pull_request.base.ref }} + run: | + if [ -n "$PR_BASE" ]; then + dupehound check --diff "origin/$PR_BASE" . + else + dupehound check --diff HEAD~1 . + fi + + scan: + name: Repo slop score + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - name: Install dupehound + run: | + curl -sL https://github.com/Rafaelpta/dupehound/releases/latest/download/dupehound-x86_64-unknown-linux-gnu.tar.gz | tar xz + sudo mv dupehound /usr/local/bin/ + - name: Scan + run: | + dupehound scan . | tee /tmp/dh-scan.txt + SCORE=$(grep -oE 'SLOP SCORE[[:space:]]+[0-9.]+%' /tmp/dh-scan.txt | head -1 | grep -oE '[0-9.]+%' || echo "n/a") + echo "## dupehound slop score" >> "$GITHUB_STEP_SUMMARY" + echo "**${SCORE}**" >> "$GITHUB_STEP_SUMMARY" diff --git a/src/browser_harness/admin.py b/src/browser_harness/admin.py index 83109c41..2b9cc047 100644 --- a/src/browser_harness/admin.py +++ b/src/browser_harness/admin.py @@ -7,27 +7,7 @@ from pathlib import Path from . import _ipc as ipc - - -def _load_env(): - repo_root = Path(__file__).resolve().parents[2] - workspace = Path(os.environ.get("BH_AGENT_WORKSPACE", repo_root / "agent-workspace")).expanduser() - for p in (repo_root / ".env", workspace / ".env"): - if not p.exists(): - continue - _load_env_file(p) - - -def _load_env_file(p): - for line in p.read_text().splitlines(): - line = line.strip() - if not line or line.startswith("#") or "=" not in line: - continue - k, v = line.split("=", 1) - os.environ.setdefault(k.strip(), v.strip().strip('"').strip("'")) - - -_load_env() +from .helpers import _load_env, _load_env_file NAME = os.environ.get("BU_NAME", "default") BU_API = "https://api.browser-use.com/api/v3" diff --git a/src/browser_harness/daemon.py b/src/browser_harness/daemon.py index 01edad1c..8b510eff 100644 --- a/src/browser_harness/daemon.py +++ b/src/browser_harness/daemon.py @@ -4,28 +4,9 @@ from pathlib import Path from . import _ipc as ipc -from cdp_use.client import CDPClient - - -def _load_env(): - repo_root = Path(__file__).resolve().parents[2] - workspace = Path(os.environ.get("BH_AGENT_WORKSPACE", repo_root / "agent-workspace")).expanduser() - for p in (repo_root / ".env", workspace / ".env"): - if not p.exists(): - continue - _load_env_file(p) - +from .helpers import _load_env, _load_env_file -def _load_env_file(p): - for line in p.read_text().splitlines(): - line = line.strip() - if not line or line.startswith("#") or "=" not in line: - continue - k, v = line.split("=", 1) - os.environ.setdefault(k.strip(), v.strip().strip('"').strip("'")) - - -_load_env() +from cdp_use.client import CDPClient NAME = os.environ.get("BU_NAME", "default") SOCK = ipc.sock_addr(NAME)