Metadata-Version: 2.4
Name: forkbridge
Version: 0.3.0
Summary: Evidence-first contract verification for Git forks and upstream updates
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/kexyz254/forkbridge
Keywords: git,fork,contracts,ci,agents
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: jsonschema>=4; extra == "test"
Provides-Extra: mcp
Requires-Dist: mcp<3,>=2.3; extra == "mcp"
Dynamic: license-file

# ForkBridge

**A clean merge is not evidence that your fork still meets its requirements.**

ForkBridge is a dependency-free CLI and GitHub Action that checks explicit file and configuration contracts against both a Git fork and a hypothetical upstream merge. It reports reproducible evidence for humans, CI pipelines and AI coding agents, without checking out or executing project code.

## Quick start

Download the wheel from [GitHub Releases](https://github.com/kexyz254/forkbridge/releases) and install it with `python -m pip install /path/to/downloaded-wheel.whl`. Use the commands below from a source checkout to install and verify.

Requires Python 3.11+ and Git 2.38+ with `merge-tree --write-tree` support. Use a trusted local repository with complete history and both refs already available.

```sh
python -m pip install .
forkbridge capabilities
forkbridge verify --repo /path/to/repo --fork HEAD --upstream upstream/main --contracts /path/to/contracts.json
```

The contract file is external policy: do not allow the candidate update to rewrite it. See [example contracts](examples/contracts.json) and [agent integration](AGENTS.md).

```json
{"version":1,"contracts":[{"id":"sqlite-enabled","kind":"json_equals","path":"config.json","pointer":"/database/sqlite","value":true}]}
```

| Contract | What it verifies |
| --- | --- |
| `exists` | Regular tracked file exists |
| `contains` | UTF-8 file contains a literal string |
| `sha256` | Exact file bytes match a SHA-256 digest |
| `json_equals` | JSON pointer resolves to the expected typed JSON value (numbers use Python JSON representation) |

## Run in GitHub Actions

This workflow checks upstream on demand from your fork's default branch. Set the two upstream values for your project, and commit a contract file at `.github/forkbridge.json` on your fork. Policy comes from the selected fork commit.

```yaml
name: Verify upstream update
on:
  workflow_dispatch:
permissions:
  contents: read
jobs:
  verify:
    runs-on: ubuntu-latest
    env:
      UPSTREAM_URL: https://github.com/UPSTREAM_OWNER/UPSTREAM_REPO.git
      UPSTREAM_REF: refs/heads/main
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
        with:
          fetch-depth: 0
          persist-credentials: false
      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: '3.11'
      - name: Fetch upstream and extract the fork policy
        run: |
          git fetch --no-tags "$UPSTREAM_URL" "$UPSTREAM_REF:refs/forkbridge/upstream"
          git show HEAD:.github/forkbridge.json > "$RUNNER_TEMP/forkbridge-policy.json"
      - uses: kexyz254/forkbridge@v0.3.0
        id: verify
        with:
          fork: HEAD
          upstream: refs/forkbridge/upstream
          contracts: ${{ runner.temp }}/forkbridge-policy.json
      - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
        if: always() && steps.verify.outputs.report != ''
        with:
          name: forkbridge-report
          path: ${{ steps.verify.outputs.report }}
```

The action fails the job for regressions, merge conflicts, inconclusive results and errors. Open the uploaded report to see the commit IDs and per-contract evidence. On self-hosted runners, use the action with a trusted local checkout and Python 3.11+ and Git 2.38+ on the path.

## Agent and CI protocol

`verify` emits one JSON object on stdout. It includes resolved fork and upstream commit IDs, merge base, candidate tree ID, contract digest and per-contract baseline/candidate blob IDs and outcomes. A passing result means only that the listed static contracts are preserved. Unknown data, a failing baseline, or unrelated histories cannot produce a pass.

| Exit | Status | Action |
| --- | --- | --- |
| 0 | `verified` | Listed contracts preserved; continue normal review |
| 10 | `regression` | Block update and investigate failed contracts |
| 11 | `conflict` | Resolve merge conflict separately |
| 12 | `inconclusive` | Investigate missing or invalid evidence |
| 2 | `error` | Correct inputs or infrastructure |

ForkBridge never fetches remote upstream refs itself, pushes, merges into the source repository, or executes contract commands. It uses a temporary bare mirror and native Git merge-tree. It may read committed secrets in the selected files, but reports only identifiers, paths and verdicts, not file contents. Contract literals and paths are not intended for secrets.

## Connect an MCP client

Install the optional MCP adapter from a checkout with `python -m pip install '.[mcp]'`. In your client's local stdio server configuration, set the command to the absolute path of the installed `forkbridge-mcp` executable and pass these arguments.

```json
{
  "command": "/absolute/path/to/forkbridge-mcp",
  "args": ["--repo", "/path/to/local/fork", "--contracts", "/path/to/trusted/policy.json"]
}
```

The server exposes `verify_merge(fork_oid, upstream_oid)` and returns the same structured evidence as the CLI. Both arguments are full Git commit IDs already present in the configured checkout. The operator selects the one checkout and the policy file outside it at startup. Run the server with a trusted local repository and complete history.

## See the difference

```sh
python examples/demo.py
```

This generates a synthetic Git fork whose upstream change merges cleanly yet disables a required feature. Expected exit status: `10`. The example prints the full JSON report. The [yt-dlp case study](docs/case-study.md) replays two updates from a real upstream history.

## Development

```sh
python -m pip install -e '.[test,mcp]'
pytest -q
```

## Boundaries

ForkBridge checks committed content using static policies. Runtime behavior, dependency analysis and automatic remediation are outside the current release. The candidate merge uses native default Git semantics in a disposable mirror; custom merge drivers and local configuration may yield a different result in an actual merge. Trusted local repositories only; use OS/container isolation when processing untrusted repositories. Timeouts and blob/config limits are not a complete resource-exhaustion defense. Shallow/partial histories, large repositories, non-UTF-8 paths and exotic Git layouts may fail or be inconclusive. CI tests the CLI and MCP adapter on Linux, Windows and macOS, and exercises the Action and Python distributions on Linux.

See [security](SECURITY.md), [contributing](CONTRIBUTING.md), [protocol](docs/protocol.md), [roadmap](docs/ROADMAP.md), and [publishing](docs/distribution.md). Apache-2.0 licensed. No affiliation with GitHub.
