Metadata-Version: 2.5
Name: pgoblin
Version: 0.8.0
Summary: Finds bugs in open source, proves the fix, and stages it in your fork for you to review.
Author: Pushkal Gupta
License-Expression: FSL-1.1-ALv2
License-File: LICENSE.md
Requires-Python: >=3.12
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.7
Requires-Dist: pyjwt[crypto]>=2.15.1
Requires-Dist: typer>=0.12
Provides-Extra: dense
Requires-Dist: numpy; extra == 'dense'
Requires-Dist: sentence-transformers>=3; extra == 'dense'
Provides-Extra: keychain
Requires-Dist: keyring>=25; extra == 'keychain'
Description-Content-Type: text/markdown

<p align="center"><img src="brand/mark.svg" alt="PGoblin" width="140"></p>

# PGoblin

**Find the bug. Prove the fix. Ship the patch.**

*The little engineering gremlin that hunts bugs, reproduces them, and crafts patches.*

PGoblin is an AI software development lifecycle for any repository, open source or your own.
Point it at a codebase and it hunts for bugs and security vulnerabilities, fixes them, or
builds a feature you ask for. It proves each change with tests that fail before and pass
after, has it reviewed by an agent that never saw the author's reasoning, and opens it as a
draft for you. After the pull request is open it keeps going: when CI fails or a reviewer
(human or a review bot such as CodeRabbit) comments, it reads the logs and the comments, sorts
real failures from flaky infrastructure, and pushes the follow-up fix. You review every change and
open the pull request yourself, under your own name. Nothing reaches upstream without you.

Its hands on GitHub are [pgremlin](https://github.com/apps/pgremlin), a public GitHub App.
pgremlin authors the commits it writes, the person running PGoblin commits them, and the
App's page names its developer, so every change can be traced to a person. Its site is
[pgremlin.com](https://pgremlin.com).

It runs on your Mac. Agent sessions and every line of agent-written code run sandboxed,
every run is measured (cost, time, which prompts produced it), and a goblin with opinions
tells you how it went.

> "Ship beats perfect." I build tools to solve my own problems, then share them with the
> world. Currently exploring how AI changes everything about software development.
>
> Peter Steinberger

That is the goal, and PGoblin automates the loop behind it: find, fix, prove, ship. One
person stays in it, as the reviewer, with observability to watch every run and triage what
needs attention.

> Status: **v0.6 in progress, private.** The whole loop runs on real issues (`goblin run`,
> `goblin fix owner/repo#N`) and on Arena replays of past fixes in lila and langflow.
> Drafts go to your fork through your own GitHub App, `pgremlin`. `/pgremlin run` fixes what
> an open PR still needs; `/pgremlin fix` on an issue works it from scratch
> (docs/PUBLISHING.md). New in v0.6: every run streams numbered events; `goblin serve` gives
> the Goblin Workshop, a visual app, a local API (replay a run event by event, open what each
> agent did, approve a bundle against its hash); models are named `provider:model`; PGhoard
> can rank by meaning (`pgoblin[dense]`); a memory part recalled into PGsmith's brief;
> trophies; `goblin ci` and `goblin new`; a headless cloud worker (docs/CLOUD.md); and
> Shapeshifter for porting code to another language (docs/SHAPESHIFT.md). What anyone can
> check is in [docs/EVIDENCE.md](docs/EVIDENCE.md). macOS first; on Linux the whole test
> suite passes with the bubblewrap sandbox (Debian 12, arm64, in Docker, 2026-12-01); a Linux
> run on a real issue and any run on Windows have not been done yet.

## Why

Writing the patch is the cheap part of a good open-source contribution. The expensive parts
come before and after it:

- checking that nobody has already claimed the bug,
- reproducing it on clean `upstream/main` and keeping the output,
- a test that fails on the base commit and passes with the fix,
- following each project's rules for titles, PR templates, DCO and AI disclosure,
- answering review, rebasing when `main` moves, and pinging a reviewer after a quiet week
  without spamming anyone.

All of this is already done by hand, as a folder of numbered files per project (evidence,
patch, title, commit message, PR body, git commands, review replies). PGoblin turns that
folder into a pipeline with state, gates and measurements.

## The loop

```mermaid
flowchart LR
    D[Discover<br/>Scout] --> T[Triage<br/>real, relevant, unclaimed?]
    T -->|no| X[Drop and record why]
    T -->|yes| R[Reproduce<br/>Reproducer]
    R --> F[Implement<br/>Forge]
    F --> M[Verify<br/>Mirror + Crucible]
    M -->|fails| F
    M --> S[Review<br/>Skeptic]
    S -->|rejects| F
    S --> H{Human approval}
    H -->|approved| C[Contribute<br/>Scribe bundle, PR]
    C --> W[Maintain<br/>Watchkeeper]
    W -->|review, CI, rebase| F
```

Every arrow is a state transition recorded by Goblin Core. Every gate leaves evidence on disk.

## The crew

Every stage is a goblin with a name. `goblin crew` introduces them.

| Goblin | Stage | Job | Status |
|---|---|---|---|
| **Gob** | Goblin Core | State machine, job store, run history | store + state types |
| **PGnosis** | Scout | Finds bugs against independent oracles: API specs, Python vs Rust parity, call-site audits | contract |
| **PGrapevine** | Triage | Decides if a lead is real, in scope and unclaimed (issue comments, linked and unlinked PRs; docs/TRIAGE.md) | **working** (claims) |
| **PGhost** | Reproducer | Minimal failing test on an immutable base SHA | Mirror cases stand in for it |
| **PGsmith** | Forge | Writes the patch in an isolated worktree | **working** |
| **PGlass** | Mirror | Differential engine: baseline vs candidate, implementation vs implementation, same inputs | **working** |
| **PGauntlet** | Crucible | Runs tests, linters and pre-commit; proves fail-before, pass-after | **working** |
| **PGrumble** | Skeptic | Independent review of the diff and evidence only, never Forge's reasoning | **working** |
| **PGquill** | Scribe | Renders the artifact bundle and applies per-repo policy packs; lints all prose | **working** |
| **PGraft** | Publisher | Stages an approved bundle as a draft PR in your fork, under the pgremlin App, linking the upstream issue | **working** ([docs/PUBLISHING.md](docs/PUBLISHING.md)) |
| **PGsift** | CI and review triage | Reads failing job logs and review-bot comments; separates real failures from infrastructure noise and keeps only the bot comments worth acting on | **working** |
| **PGmend** | Follow-up | `/pgremlin run` on an open PR: runs the loop on the PR's head and pushes one more commit | **working** |
| **PGuardian** | Watchkeeper | Tracks open PRs: head SHA history, force pushes, CI, reviews, quiet days | **working** |
| **PGladiator** | Goblin Arena | Replays past contributions with the fix hidden and scores the system | **working** (lila and langflow replays) |

The design is in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md). The differential engine is in
[docs/MIRROR.md](docs/MIRROR.md).

## The authorship contract

These rules are enforced in code, and the tests check them.

1. **Every commit names a person.** Commits PGoblin writes are authored by `pgremlin[bot]`
   and committed by the contributor (with `-s` where the project requires DCO), so GitHub
   shows "pgremlin[bot] authored and <you> committed". Commits the contributor writes are
   theirs alone. Commit messages carry no AI trailer; the PR carries the disclosure.
2. **Disclosure follows the project's policy, never less.** lichess and pandas each ask
   for AI assistance to be declared in the PR (pandas also wants a template-only body);
   where a project has no policy, as langflow, the PR still says so. Scribe fills that section
   from the repo's policy pack, and it cannot be turned off. If a project forbids agent
   contributions, PGoblin does not contribute there.
3. **Nothing is published without a human.** No PR, comment, push or label goes out until
   the contributor approves the exact text.
4. **Never merge.** Not with permission, not on a green build.
5. **Other people's work stays theirs.** PGoblin does not adopt, rewrite or replace a PR it
   did not open for its contributor.

The details are in [docs/AUTHORSHIP.md](docs/AUTHORSHIP.md).

## Getting started on a Mac

Installing from a wheel on macOS, Linux or Windows (WSL2) is in [docs/INSTALL.md](docs/INSTALL.md).
From a checkout:

```sh
uv sync
uv run goblin setup     # first time: checks, then init, doctor, app-create, app-install, asking before each
uv run goblin init      # a goblin.toml with your GitHub login and the projects you have checked out
uv run goblin doctor    # sandbox, tools, GitHub sign-in, config, publish app: what is missing and how to fix it
uv run goblin outcomes  # what happened to every draft the bot opened (GET only), kept as a report
uv run goblin crew      # meet the goblins
```

## Quickstart (Watchkeeper)

Requires Python 3.12+, [uv](https://docs.astral.sh/uv/) and an authenticated
[gh](https://cli.github.com/). PGoblin reads the token from `gh auth token` and makes GET
requests only.

```sh
uv sync
uv run goblin watch          # poll every PR listed in goblin.toml, record what changed
uv run goblin report         # write reports/status.md
uv run goblin status 16682   # history of one PR
```

`goblin.toml` lists the pull requests to watch:

```toml
[[watch]]
repo = "langflow-ai/langflow"
prs = [16681, 16682]
policy = "langflow"
```

vllm, pytorch, n8n and airflow are off limits: loading a config that watches or checks
out one of them stops with an error (`src/pgoblin/core/limits.py`).

For each PR the report shows:

- the state, the head SHA and how it got there (fast-forward, rebase or rewrite),
- CI split into fixable, flaky, blocked on a maintainer and pending,
- reviews waiting for a reply,
- days since the last activity (a nudge is due at seven),
- whether `main` has moved far enough to need a rebase.

## Mirror: two implementations, same inputs

Mirror runs two systems on the same cases, normalizes their outputs (ids, timestamps, error
wording, null against absent) and reports where they differ, plus `expect` oracles that catch
a bug both sides share. It was first built on vLLM's Python and Rust frontends, before vLLM
went off limits; ports of libraries now go through Shapeshifter
([docs/SHAPESHIFT.md](docs/SHAPESHIFT.md)), and Mirror's design is in
[docs/MIRROR.md](docs/MIRROR.md).

## Arena: the whole loop on a past contribution

```sh
uv run goblin arena run evaluation/arena/langflow-16465.toml --agent-model opus --max-cost 10
```

A task names a base SHA, the claim and the test commands. The run clones only the base
commit (so no branch holding the real fix is reachable), reproduces, lets PGsmith write a
test and a patch, runs PGauntlet's gates and asks PGrumble to review blind. It writes a Scribe bundle and stops at
`awaiting_human`. Afterwards it applies the contributor's own test to Forge's patch, as a score
the agents never see.

## Security

PGoblin will run code from repositories it does not control, and it reads text written by
strangers. Issue bodies, PR descriptions, review comments and source comments are treated as
untrusted input. Sandboxes never hold credentials. Analysis and publishing are separate
planes with separate tokens. Every run is pinned to an immutable SHA. See
[docs/SECURITY.md](docs/SECURITY.md).

## Measurement

The system is judged by the metrics in [docs/EVALUATION.md](docs/EVALUATION.md):
reproduction rate, acceptance rate, regression rate, human-intervention rate, time to verified
patch, cost per accepted patch and review precision. Goblin Arena replays the contributor's
own PRs with the fix hidden. No numbers appear here until they have been measured. With
fewer than ten tasks they are counts, not rates.

Certified Arena suite 2, measured on 28 November before vLLM went off limits: three vLLM
replays at `cfbc42099a`, Opus, one repair round
([details](evaluation/2026-11-28-arena.md)).

| Metric | Value |
|---|---|
| Bug reproduced by Mirror | 3 of 3 |
| Patch passed every gate (Crucible, Mirror targets fixed, Skeptic) | 2 of 3 |
| Upstream's own test passes on Forge's patch | 3 of 3 (two scored on test files only) |
| Agent cost, total | $5.23 |
| Patch acceptance upstream | not yet measured |

## Roadmap

| Milestone | Status, 2 December 2026 |
|---|---|
| M1, the spine: events, local API, sandbox interface, models per stage | built |
| M2, the Goblin Workshop | v3 built; polish in progress |
| M3, memory | built and recalled into runs |
| M4, optimisation | measured on 12 Arena runs: no gain yet, so it stays off |
| M5, everywhere: Linux, Windows (WSL2), installers | built; Windows never run |
| M6, CI, `goblin new`, a cloud worker | built; the worker never deployed |
| M7, Shapeshifter ports | three public ports (Rust, TypeScript, Go), every recorded call matching |

Details and non-goals are in [docs/ROADMAP.md](docs/ROADMAP.md).

## Layout

```
src/pgoblin/
  core/            state machine, models, SQLite store, config
  integrations/    GitHub REST client (read-only in v0)
  agents/          scout, triage, reproducer, forge, skeptic, watchkeeper
  mirror/          differential verification engine
  scribe/          artifact bundles, policy packs, prose linter
  arena/           evaluation runner
tests/             pytest, HTTP recorded with respx
docs/              design documents
```

## Development

```sh
uv sync
uv run pytest
uv run ruff check .
uv run python -m pgoblin.scribe.tells README.md docs/*.md
```

## License

Functional Source License 1.1, Apache 2.0 future license (FSL-1.1-ALv2): each release
becomes Apache-2.0 two years after it is published. See [LICENSE.md](LICENSE.md),
[TRADEMARKS.md](TRADEMARKS.md) and [docs/RELEASE.md](docs/RELEASE.md). The repository is
private until the release plan says otherwise.
