github-core-clone
README.md
# github-core-clone
A deterministic, stdlib-only GitHub core clone: git smart HTTP, REST v3,
GraphQL, and MCP in a single Node.js process. Built for the make.fun
bounty [github-core-clone-01](https://make.fun/bounty/github-core-clone-01).
[](https://make.fun/bounty/github-core-clone-01)
[](https://make.fun/bounty/github-core-clone-01)
[](https://make.fun/bounty/github-core-clone-01)
## What it does
- **Git smart HTTP** (`/{owner}/{repo}.git`): upload-pack protocol v2
(ls-refs, fetch, shallow/deepen) and v0, receive-pack v0 with
fast-forward-only pushes. Packfile parsing/packing, pkt-line framing,
and the object store (loose objects + packfiles, zlib, SHA-1) are all
implemented by hand — no git binary, no npm dependencies.
- **REST v3** (`/api/v3`): repositories, branches, commits, refs, contents,
labels, issues, comments, pull requests, and squash merges, with
GitHub-shaped pagination (`Link: rel="next"`).
- **GraphQL** (`POST /api/graphql`): viewer, repository, issue/PR
connections with cursor pagination, `__type` introspection, and the
`createIssue` / `closeIssue` / `createPullRequest` / `mergePullRequest` /
`addComment` mutations.
- **MCP** (`POST /mcp`): JSON-RPC 2.0 Streamable HTTP, revision
`2026-07-28` (`server/discover`) and the legacy `initialize` handshake,
with seven tools (`create_repo`, `get_repo`, `create_issue`,
`list_issues`, `get_issue`, `create_pull_request`, `merge_pull_request`)
acting on the same in-memory store as REST.
## Determinism
One process, one in-memory store. Dates come from `MAKEFUN_TRIAL_NOW`
(never the wall clock) and ids from counters seeded at startup — no
`Math.random()`, no random UUIDs — so a trial replays byte-identically.
## Run it
```sh
node --experimental-strip-types main.ts
```
Requires Node >= 22.18. `MAKEFUN_SHOP_TOKEN` sets the Bearer token the
REST, GraphQL, and MCP surfaces accept; `MAKEFUN_TRIAL_NOW` sets the
logical clock. With `MAKEFUN_ENV_URL` set, the process registers its
port with the harness and exits when the harness reports done.
## Layout
- `main.ts` — entry point: lifecycle (bind, register, poll done, exit).
- `app.ts` — HTTP server, routing, auth, body parsing.
- `src/git.ts` — git object model, pkt-lines, packfiles, graph walks.
- `src/git-http.ts` — git smart-HTTP handlers.
- `src/store.ts` — in-memory store: repos, issues, PRs, contents, merges.
- `src/rest.ts` — REST v3 handlers.
- `src/graphql.ts` — GraphQL parser + executor.
- `src/mcp.ts` — MCP JSON-RPC handlers and tools.
- `src/util.ts` — HTTP helpers, base64url ids, line diff.