Skip to content
nemesisbugPublic

About

Anvil — a GitHub-compatible git forge with one store and four doors: git smart HTTP, REST v3, GraphQL and MCP, zero dependencies, one process. make.fun bounty entry.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Anvil — a git forge with one store and four doors

Anvil is a standalone GitHub-compatible git forge in a single Node process: no UI, no database, no dependencies, no git binary. One in-memory store holds every repository, object, ref, issue and pull request — and four protocols are four doors into the same room:

  • git smart HTTP (upload-pack / receive-pack, v0 and v2),
  • REST v3,
  • GraphQL,
  • MCP (Streamable HTTP, JSON-RPC 2.0).

Create a repository over MCP and it reads back over REST with the same ids. Push a branch over git and the pull request that names it sees the new tip. Merge it over GraphQL and the REST view shows it merged. There is no translation layer and no drift, because there is nothing to translate between: every surface reads and writes the same objects.

The name is the point. A forge shapes metal on an anvil: one heavy, unmoving surface, and every tool strikes the same place. Anvil is built the same way — one store, struck from four sides.

Run

Node 22.18+ (native TypeScript type stripping; nothing to install):

MAKEFUN_SHOP_TOKEN=<token> node main.ts

Without MAKEFUN_ENV_URL the process exits 1: that variable is the grading harness's env origin. The entry binds an ephemeral port, registers it with POST $MAKEFUN_ENV_URL/register {"port": N}, then polls GET $MAKEFUN_ENV_URL/done until {"done": true} and exits 0.

Layout

File What it does
main.ts Entry/env lifecycle: bind, register, wait for done.
app.ts HTTP server, routing, the REST v3 API, git endpoints.
store.ts The whole state: git objects, refs, repos, issues, pull requests, labels, comments. The anvil.
git.ts pkt-line framing, packfile read/write, v0/v2 advertisements, ls-refs, fetch planning, receive-pack.
graphql.ts A small GraphQL parser and executor for the query, mutation and introspection documents a client sends.
mcp.ts MCP: server/discover, initialize, tools/list, tools/call.
DESIGN.md Why it is built this way — the deliberate choices.

The idea in one paragraph

Most forges are several systems pretending to be one: a git server, an API server, a database, and a translation layer between them that slowly disagrees with itself. Anvil is one system. The store owns the truth; the four protocols are thin views over it, each speaking its own wire format faithfully (pkt-lines and packfiles, JSON and Link headers, GraphQL documents, JSON-RPC) and none of them owning any state of its own. That is why a merge computed over REST, a conflict detected over GraphQL and a fetch served over git always agree: they are three readings of one history, not three histories.

Protocol notes

  • Git. Protocol v2 when the client sends Git-Protocol: version=2, v0 otherwise; receive-pack is v0 only. Packs are written with full objects only (no deltas on the wire out); REF_DELTA and OFS_DELTA are resolved on the way in. Fetch plans follow the usual rule: walk from the wants, stop at what the client holds, honour deepen and the client's shallow boundaries (emitting shallow/unshallow lines), and send the tree closures of the included commits minus the closures of the held ones. Pushes apply the fast-forward rule per ref (non-fast-forward refusals still unpack their objects) and report per-ref ok/ng lines with report-status.
  • REST v3. Every reply is application/json with a non-empty X-GitHub-Request-Id; errors carry {message}. Auth is Authorization: Bearer <MAKEFUN_SHOP_TOKEN>; a missing or wrong token is 401, and a repository under another owner is a 404, never a 403. Listings paginate with per_page/page and an absolute-URL Link header.
  • GraphQL. viewer, repository, node, __type/__schema introspection, cursor-paginated issues/pullRequests, and the createIssue, closeIssue, createPullRequest, mergePullRequest and addComment mutations. Global ids are opaque base64url strings (Repository:<dbid>, Issue:<repoId>:<number>, …), stable across reads.
  • MCP. Modern revision 2026-07-28 (server/discover first, legacy initialize also accepted), eight tools: create_repo, get_repo, create_issue, list_issues, get_issue, create_pull_request, merge_pull_request, list_pull_requests. Tool results carry both content text and structuredContent.

Deliberate choices

  • Deterministic time. Every timestamp derives from a fixed trial base plus a creation sequence, and REST-made commits stamp from a fixed epoch one second apart. The same operations always produce the same bytes, so the forge is reproducible, not just repeatable.
  • Merges read the live base. A pull request's merge and its conflict check are computed against the base branch as it is now, not the tip recorded when the request was opened — so a second request that edits the same file the first one already merged is correctly conflicted.
  • Full objects on the wire. Anvil never writes deltas into a pack. That costs a few bytes and buys a pack writer with no way to emit a broken delta chain.
  • No disk, no network, no binaries. The store is memory; the only processes are this one. There is nothing to install, migrate or back up, and nothing that can disagree with the store.

See DESIGN.md for the full reasoning.

Identity

The token owner is the deterministic scenario identity from the competition kit (adaiversen, id 1000); the token itself is only ever compared against MAKEFUN_SHOP_TOKEN, never stored.

License

MIT. See LICENSE.

About

Anvil — a GitHub-compatible git forge with one store and four doors: git smart HTTP, REST v3, GraphQL and MCP, zero dependencies, one process. make.fun bounty entry.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages