From acd7238eaa60c387544fac3adbf00c4dc279f76c Mon Sep 17 00:00:00 2001 From: David Case Date: Sun, 20 Sep 2026 01:52:15 -0400 Subject: [PATCH 1/2] Agent guide: AGENTS.md as the canonical file, plus a gibhub skill CLAUDE.md was 46 lines and out of date. Replace it with AGENTS.md, the arrangement the gib CLI uses, and make CLAUDE.md a symlink to it. Covers what the code actually does: every route and what it renders, the lib modules that matter, the head token's exact fields and vocabulary, the overlay and ORDFS routes the site calls and what each returns, and the conventions already in the code (server components by default, server-side handle resolution behind one shared cache, react-query keys, and the standing rule not to reimplement anything the @1sat SDK ships). Adds skills/gibhub/SKILL.md for agents working in this codebase, listed in a catalog table in AGENTS.md. This is not a monorepo, so skills/ at the root is the only copy; there is nothing to mirror it to. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01EM5trZ4BfZpW7pBjq2onqX --- AGENTS.md | 332 +++++++++++++++++++++++++++++++++++++++++ CLAUDE.md | 47 +----- README.md | 8 + skills/gibhub/SKILL.md | 133 +++++++++++++++++ 4 files changed, 474 insertions(+), 46 deletions(-) create mode 100644 AGENTS.md mode change 100644 => 120000 CLAUDE.md create mode 100644 skills/gibhub/SKILL.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..fa8fd73 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,332 @@ +# AGENTS.md — working on gibhub.net + +gibhub.net is the web viewer for [gib](https://github.com/b-open-io/gib), +on-chain git on BSV. It reads repositories, branches and files from the +1sat-stack overlay at `https://api.1sat.app` and connects to the visitor's +BRC-100 wallet in the browser to mint and burn branch heads. + +For what the site *shows*, read [README.md](README.md) and +[skills/gibhub/SKILL.md](skills/gibhub/SKILL.md). This file is for changing it. + +## Skills + +| Skill | For | +| --- | --- | +| [`skills/gibhub`](skills/gibhub/SKILL.md) | Using and changing this site: routes, lib modules, the overlay and ORDFS calls, the wallet operations. | + +This repository is not a monorepo, so `skills/` at the root is the only +copy — there is nothing to mirror it to. Add a skill as +`skills//SKILL.md` with frontmatter `name` and a trigger-rich +`description`, and list it here. + +## Terminology (non-negotiable) + +Always **"repository origin"**, never bare "origin". Three things called +"origin" live within a page of each other: a repository's genesis +`ordfs/dir` root outpoint (this one), an ordinal's own origin, and git's +conventional remote name. Comments, error strings, docs and commit messages +all spell it out. The route parameter is `[origin]` and `HeadRecord.origin` +is the field name; the prose around them says "repository origin". + +## Build, test, lint + +```sh +bun install +bun dev # next dev on :8266 +bun run lint # biome check +bun run typecheck # tsc --noEmit +bun test # bun's runner over lib/*.test.ts +bun run build # next build +bun run lint:fix # biome check --write . +bun run start # next start, after a build +``` + +All of lint, typecheck, test and build must be clean before a commit. +Bun, not npm. + +`.github/workflows/verify.yml` runs the same four on every pull request and +every push to `main`, and **pins `bun-version: 1.4.2`** with +`bun install --frozen-lockfile`. `bun.lock` is written by that bun; a +different bun rewrites the lockfile and the frozen install fails. The CI +build is given `NEXT_PUBLIC_ONESAT_STACK_URL=https://api.1sat.app` and +`NEXT_PUBLIC_APP_URL=https://gibhub.net`. + +`main` auto-deploys to https://gibhub.net through Vercel. A merge is a +deploy; there is no separate release step. + +## Layout + +### `app/` — routes + +| Route | Renders | +| --- | --- | +| `/` | Explore: 20 most recent repositories and 20 most recent pushes. | +| `/r/[origin]` | Repository: branch heads, the default branch's file tree, the README. | +| `/r/[origin]/tree/[ref]/[[...path]]` | Directory listing at a ref and path. A file path redirects to `blob`. | +| `/r/[origin]/blob/[ref]/[...path]` | One file: text with syntax highlighting, image, or a download link. A directory path redirects to `tree`. | +| `/r/[origin]/commits/[...ref]` | Push history of one branch, paged by overlay `score` through `?from=`. | +| `/r/[origin]/commit/[head]` | One head: its commit object, the same commit on other heads, the heads that build on it, Branch. | +| `/c/[sha]` | A git commit as a DAG node, independent of repository: every head publishing it, its parents, its children. | +| `/u/[identity]` | A publisher: repositories and pushes under one 66-hex identity key. | +| `/me` | The connected wallet's own branches (`components/my-repos.tsx`). Client-only. | +| `/api/handles` | `GET ?handle=…` — BRC-169 resolution through the server's shared cache. | +| `/manifest.json` | Web app manifest, the BRC-73 grouped permissions block, and `babbage.trust`. | + +`app/layout.tsx` wraps everything in `ThemeProvider` → `QueryProvider` → +`WalletProvider` and the site header/footer. `app/error.tsx` and +`app/not-found.tsx` are the boundaries. + +A `[ref]` is a **head outpoint** (`txid_vout`) in every generated link, so +links never rot. A branch name is accepted too and resolves to that +branch's current head — see `lib/resolve-ref.ts`. + +### `lib/` — the modules that matter + +| Module | Owns | +| --- | --- | +| `stack.ts` | `STACK_URL` (`NEXT_PUBLIC_ONESAT_STACK_URL`, default `https://api.1sat.app`), `APP_URL`, and `GIB_BASKET`. | +| `gib-api.ts` | Typed client for the overlay REST API under `/1sat/gib`. The `HeadRecord`, `RepoRecord`, `Commit` and `Spend` shapes. 404 → `null`, anything else throws. | +| `ordfs.ts` | ORDFS reads: `/content/…` URLs, `ordfs/dir` manifest decoding, bulk metadata, path walking, text fetch, `.gib` metadata. | +| `gib-wallet.ts` | The three wallet operations: `mintHead`, `burnHead`, `branchFromHead`. The token vocabulary lives here. | +| `gib-head.ts` | Decodes a head from its own locking script — PushDrop fields plus the inscribed git commit — with no overlay round trip. | +| `resolve-ref.ts` | A URL ref → a `HeadRecord`: outpoint (immutable) or branch name (current head). | +| `handles.ts` | BRC-169: the handle grammar, manifest discovery, the resolve endpoint, the cache, and `verifyHandle`. Isomorphic and pure where it can be. | +| `handles-server.ts` | The one shared resolver instance, on `globalThis`. Server only. | +| `routes.ts` | Every internal URL. Build links here, never by hand. | +| `format.ts` | `txid_vout` handling (`toOrdinalOutpoint`, `outpointTxid`, `outpointVout`), shortening, `timeAgo`, commit-message splitting. | +| `explorer.ts` | Block explorer links (bananablocks.com). | +| `empty.ts` | The browser stand-in `next.config.ts` aliases `xdelta3-wasm` to. | + +`lib/format.test.ts`, `lib/ordfs.test.ts`, `lib/gib-head.test.ts` and +`lib/handles.test.ts` are the test suite. They are pure; nothing in them +touches the network or a wallet. + +### `components/`, `providers/` + +`components/ui/` is shadcn/ui (new-york), copied from 1satwallet.com and +excluded from Biome in `biome.json`. Everything above it is this site's own. + +The wallet-touching ones are `connect-wallet-button.tsx`, `my-repos.tsx`, +`branch-button.tsx` and `delete-branch-button.tsx`; all four are `"use +client"` and reach the wallet only through `useWallet()` from `@1sat/react`. + +`providers/wallet-provider.tsx` is `@1sat/react`'s `WalletProvider` with +`autoReconnect autoDetect`. `providers/query-provider.tsx` is a TanStack +Query client with `staleTime: 30s, retry: 1`. + +There is no `hooks/` directory. Client state is react-query plus component +state; add a hook only when two components need the same one. + +## The data model + +A **repository origin** is the outpoint of the genesis `ordfs/dir` root, +written `txid_vout`. It identifies the repository and never changes. + +A **commit head** is a 1-satoshi PushDrop output. Its fields, in order, are + +``` +["gib", , , , ] +``` + +as UTF-8 strings, locked under protocol `[1, "gib branch"]` with +`keyID` = the **root** outpoint and counterparty `anyone`, with the git +commit object inscribed on the same output after the PushDrop lock. The +coin is filed in basket `gib` under tags `origin:`, `branch:` and +`commit:`, minted under the action label `gib push` and burned under +`gib delete`. + +Pushing spends the previous head into the next one, so **a head's spend +chain is the branch history**. `HeadRecord.prev` walks back; +`HeadRecord.spend` walks forward — `spend.next` present is a push, +`spend.next` absent is a branch deletion. + +`root` is the `ordfs/dir` outpoint of the tree *at that head*. **File +browsing always goes through `head.root`**, never through the repository +origin. Every page does this: `app/r/[origin]/page.tsx`, +`tree/…` and `blob/…` all call `resolvePath(head.root, path)` or +`loadDirectory(head.root)`. + +`lib/ordfs.ts:loadRepoMeta` is the one deliberate exception: it reads +`.gib` through the repository origin, because it wants the genesis `.gib` +and wants a name without an overlay round trip. + +## How it connects to everything else + +### The overlay (`/1sat/gib` on `STACK_URL`) + +All of these are `GET`, JSON, and wrapped in `lib/gib-api.ts`. + +| Route | Returns | +| --- | --- | +| `/repos` | `RepoRecord[]` — recently active repositories. | +| `/identity/{identity}/repos` | `RepoRecord[]` — repositories one identity publishes to. | +| `/repo/{origin}` | `RepoResponse`: the repository plus `branchHeads`. | +| `/repo/{origin}/branches` | `HeadRecord[]` — current heads, optionally `?identity=`. | +| `/repo/{origin}/branch/{name}` | `BranchResponse`: the current `head` and the `history` of that branch. | +| `/head/{outpoint}` | One `HeadRecord`. | +| `/commit/{sha}` | `CommitResponse`: the heads publishing that commit and the heads building on it. | +| `/heads` | `HeadRecord[]` filtered by `origin`, `branch`, `identity`, `unspent`. | + +Paging is `limit` / `from` (an overlay `score`) / `rev`. `404` becomes +`null`; anything else throws. Server components pass a `revalidate` window +(30 s by default) which is applied only when `typeof window === "undefined"`. + +### ORDFS (`/content` and `/1sat/ordfs` on `STACK_URL`) + +| Request | Returns | +| --- | --- | +| `GET /content/{outpoint}` | The resolved file bytes, patch chains applied by the gateway. | +| `GET /content/{root}/path/to/file` | The same, resolved through a directory tree. | +| `GET /content/{outpoint}?raw=true` | The record's own bytes — how a directory manifest is read. | +| `POST /1sat/ordfs/metadata` | `{ outpoints }` → content type and length for up to 100 outpoints. | +| `GET /1sat/ordfs/metadata/{outpoint}` | The same for one. | + +The gateway applies `ordfs/patch` (vcdiff) chains itself. The site never +does: `next.config.ts` aliases `xdelta3-wasm` to `lib/empty.ts` in the +browser bundle, because `@1sat/actions` imports it lazily and its Node +loader wants `fs`. + +### The wallet + +`@1sat/react`'s `WalletProvider` auto-detects the 1Sat browser extension, +a desktop wallet on `localhost:3321` and XDM hosts. Connecting calls +`waitForAuthentication`, then `getPublicKey({ identityKey: true })`, and +polls `isAuthenticated`. Everything after that goes through +`lib/gib-wallet.ts`. + +The permissions the site needs are declared as a BRC-73 grouped request in +`app/manifest.json/route.ts`, so a wallet can ask once at connect time +instead of prompting per call. Adding a wallet call means adding it there — +see [Wallet permissions](#wallet-permissions). + +### Heads without the overlay + +`lib/gib-head.ts:decodeHeadScript` rebuilds a whole `HeadRecord` from a +locking script: the PushDrop prefix before the ord envelope gives the five +fields, and `Inscription.decode` plus `parseCommit` gives the commit. +`/me` uses it, so **"my repositories" works with no overlay at all** — a +repository you published is yours to see before any indexer catches up. +`score` and `height` are `0` there (unknown locally) and `spend` is absent +(the wallet only returns spendable coins). + +### The gib CLI + +The Go CLI at https://github.com/b-open-io/gib writes the heads this site +reads, and its `internal/token` package is the reference for the token +vocabulary. `lib/gib-wallet.ts` mirrors it field for field so a head minted +in the browser is indistinguishable from a CLI push. Its fixtures +(`internal/testdata/ts-fixtures.json`) are the pinned bytes; if this site +and that package disagree, this site is wrong. + +## Conventions + +**Server components by default.** Every page under `app/` except `/me` is a +server component with `export const revalidate = 30`, fetching through +`lib/gib-api.ts` and `lib/ordfs.ts` with `next: { revalidate }`. `"use +client"` is for the wallet, TanStack Query, and interactive widgets, and +nothing else. + +**Handle resolution is server-side.** `lib/handles-server.ts` holds one +resolver on `globalThis` so a page listing twenty commits by one author +asks that author's domain once, and so the manifest and binding caches are +shared across requests. Client components do not resolve handles +themselves; they call `/api/handles` and apply the verification rule +locally with `matchAuthorHandles`. + +**Client data is TanStack Query.** Keys in use: `["gib-basket", identityKey]`, +`["repo-meta", origin]`, `["handles", handleKeys]`. After a mint or a burn, +invalidate `["gib-basket"]`. + +**Do not reimplement anything the @1sat SDK provides.** This is the +standing rule and it has teeth: + +- Manifest decoding is `dirDecode` / `dirNameString` from `@1sat/actions`. +- Script building and decoding are `pushDropLock`, `pushDropDecode`, + `unlockByScript`, `completeSignedAction`, `pushDropCustomInstructions`, + `stampManagedOutputIds` from `@1sat/actions` and `Inscription` from + `@1sat/templates`. +- Never hand-roll PushDrop, B, or OP_RETURN scripts here. + +If the SDK is missing something, add it to the SDK. + +**Outpoints are `txid_vout` everywhere in this codebase.** Convert at the +boundary with `toOrdinalOutpoint` (`txid.vout` is accepted on the way in). +The wallet's own outpoint form is `txid.vout` — `gib-wallet.ts` converts +both ways at each `listOutputs` / `createAction` call. + +**Biome**: tabs, double quotes, organized imports. `components/ui` is +excluded. `bun run lint:fix` before committing. + +**Identity display** is the raw identity key through `IdentityLink`, with a +verified BRC-169 handle in front of it when there is one. + +## Wallet permissions + +`app/manifest.json/route.ts` serves the site manifest, which carries a +BRC-73 `permissions` block. A BRC-100 wallet fetches +`https://gibhub.net/manifest.json` when the app first connects and asks for +everything in it as one grouped request. + +Declare exactly what the code calls and nothing more; an over-broad +manifest is worse than none. The current set is derived from +`lib/gib-wallet.ts` and the `@1sat/connect` handshake: + +| Declared | Because | +| --- | --- | +| protocol `identity key retrieval`, level 1, counterparty `self` | `getPublicKey({ identityKey: true })` on connect. | +| protocol `gib branch`, level 1, counterparty `anyone` | `pushDropLock` and `unlockByScript` sign under `[1, "gib branch"]`. | +| basket `gib` | `listOutputs({ basket: "gib" })` on `/me`, and every minted head is filed there. | +| label `gib push` | `mintHead`. | +| label `gib delete` | `burnHead`. | +| spending authorization | `mintHead` creates a 1-satoshi output the wallet funds, and both actions pay fees. | + +`babbage.trust` is added when `NEXT_PUBLIC_TRUST_PUBLIC_KEY` is set, so a +desktop wallet can treat this origin as trusted. + +Changing an action label, a protocol name, or the basket invalidates every +user's existing grants and every user's entry in their wallet's permission +list. Treat them as a published interface, exactly as the CLI's +`internal/token` does. + +## Things that will bite you + +**The repository origin is the genesis tree, not the current one.** +Resolving a path through the repository origin outpoint gives you the files +as they were at `gib init`, forever. Browse through `head.root`. The one +place that reads through the repository origin on purpose is +`loadRepoMeta`, which wants the genesis `.gib`. Every other use is a bug, +and it is a quiet one: the page renders, with stale files. + +**Handle verification is per head, not per commit.** `verifyHandle` counts +a handle as verified only when the author's domain resolves it to the +identity key that signed *the head being viewed*. The same commit therefore +shows a verified `@alice@1sat.name` on Alice's own head and plain +`alice@1sat.name` on someone else's head that republishes it. That is the +intended behaviour, it matches what git shows, and `/c/[sha]`'s summary +block deliberately has no head context and so never verifies. Do not +"fix" it by resolving once per commit. + +**The `gib` basket is hard-coded.** `GIB_BASKET` in `lib/stack.ts` is a +protocol constant shared with the CLI, not a setting. It reads from no +environment variable and must not grow one. + +**CI pins bun 1.4.2.** `bun.lock` is written by that version and CI installs +`--frozen-lockfile`. If a local `bun install` rewrites the lockfile, the +lockfile is wrong or your bun is — check `bun --version` before committing a +lockfile change. + +**`revalidate` is server-only.** `lib/gib-api.ts` and `lib/ordfs.ts` attach +`next: { revalidate }` only when `typeof window === "undefined"`. The same +functions run in client components with plain `fetch`, so a client call has +no ISR behind it; that is what react-query's `staleTime` is for. + +**Two wallet calls, one of which costs money.** `branchFromHead` fetches the +commit object from ORDFS, then mints. A failed mint after a successful +fetch costs nothing; a failed anything after `createAction` returns does +not. There is no resume state in the browser — the CLI has one, this does +not. + +**Every page is a server fetch against a live overlay.** `bun run build` +does not prerender repository pages (they are dynamic), but `bun dev` +against a stack that is down looks like a site-wide 500. Check +`STACK_URL` first. diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index bc8531a..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,46 +0,0 @@ -# gibhub.net - -GitHub-style viewer for gib (on-chain git on BSV). Read-only against the 1Sat -stack: ORDFS for content, the `gib` overlay (`/1sat/gib`) for repositories, -branches, and push history. Design source of truth: `gib-cli/docs/plans/`. - -## Commands - -```bash -bun install -bun dev # next dev on :8266 -bun run lint # biome check -bun run typecheck # tsc --noEmit -bun run build -bun test -``` - -## Layout - -- `app/` routes: `/` explore, `/r/[origin]` repo, `/r/[origin]/tree/[ref]/[[...path]]`, - `/r/[origin]/blob/[ref]/[...path]`, `/r/[origin]/commits/[...branch]`, - `/r/[origin]/commit/[head]`, `/c/[sha]` (commit DAG node), `/u/[identity]`, `/me` (wallet), `/manifest.json`. -- `lib/gib-api.ts` typed overlay client; `lib/ordfs.ts` manifests + content; - `lib/resolve-ref.ts` ref → head; `lib/routes.ts` URL builders. -- `components/ui/` is shadcn (copied from 1satwallet.com, excluded from Biome). -- Wallet: `@1sat/react` `WalletProvider`/`useWallet`. No custom wallet code. - -## Conventions - -- Server components fetch with `next: { revalidate }`; client data via TanStack Query. -- Refs in generated links are head outpoints (`txid_vout`), never branch names. -- Outpoints are `txid_vout` everywhere in this codebase; convert at the boundary - with `toOrdinalOutpoint`. -- Identity display is the raw key via `IdentityLink`; a name registry fronts it later. -- BRC-169 handles (`lib/handles.ts`, `lib/handles-server.ts`): the handle is the - git author/committer email as written (`alice@1sat.name` or `@alice@1sat.name`). - It is "verified" only when the domain's resolve endpoint returns the identity - key that signed the head being viewed; otherwise the author is plain text. - Resolution is server-side with an in-memory cache (manifest + binding, ttl - clamped to 60 s..24 h, failures cached 5 min); the client reaches it via - `/api/handles`. No search, reverse, alias, messaging, or delegation. -- Manifest decoding comes from `@1sat/actions` (`dirDecode`); do not reimplement it. - `lib/gib-wallet.ts` mints/burns heads with the CLI's exact conventions; keep them in sync with gib-cli `src/token.ts`. -- `next.config.ts` stubs `xdelta3-wasm` in the browser bundle; the site never applies patches itself. -- Script building and decoding come from `@1sat/actions` / `@1sat/templates`; never hand-roll PushDrop, B, or OP_RETURN scripts here. -- Tabs, double quotes (Biome). Bun, not npm. diff --git a/CLAUDE.md b/CLAUDE.md new file mode 120000 index 0000000..47dc3e3 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md \ No newline at end of file diff --git a/README.md b/README.md index b0c3124..cbcb309 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,14 @@ bun run lint && bun run typecheck && bun run build enabled. `NEXT_PUBLIC_TRUST_PUBLIC_KEY`, when set, adds a `babbage.trust` block to `/manifest.json` so the 1Sat desktop wallet trusts this origin. +`/manifest.json` also carries a BRC-73 `permissions` block, so a BRC-100 +wallet asks once, as one grouped request, for everything the site needs: +the identity key, protocol `gib branch`, basket `gib`, the `gib push` and +`gib delete` action labels, and a spending authorization for minting heads. + +Working on the code: [AGENTS.md](AGENTS.md), and +[skills/gibhub](skills/gibhub/SKILL.md) for agents. + ## Data flow | Need | Source | diff --git a/skills/gibhub/SKILL.md b/skills/gibhub/SKILL.md new file mode 100644 index 0000000..8e9b149 --- /dev/null +++ b/skills/gibhub/SKILL.md @@ -0,0 +1,133 @@ +--- +name: gibhub +description: "This skill should be used when working on gibhub.net, the web viewer for gib (on-chain git on BSV) — its Next.js routes, its overlay and ORDFS clients, its BRC-100 wallet operations, or its BRC-169 author handles. Triggers on 'gibhub', 'gibhub.net', 'on-chain git viewer', 'browse a repo on chain', 'repository origin', 'commit head', 'branch head', 'gib overlay', '/1sat/gib', 'ORDFS content', 'BRC-169 handles', 'gib basket', 'gib push label'. The companion CLI is the Go gib at github.com/b-open-io/gib; use its own skill for publishing." +--- + +# gibhub.net + +## What it does + +gibhub.net browses git repositories that gib published on chain. It reads +the 1sat-stack overlay for repositories, branches and push history, reads +ORDFS for file content, and talks to the visitor's BRC-100 wallet to mint +and burn branch heads. + +- A repository is identified by its **repository origin**: the outpoint of + its genesis `ordfs/dir` root, `txid_vout`. Say "repository origin", not + "origin" — an ordinal has an origin and git has a remote named `origin`. +- A branch head is a 1-satoshi PushDrop output with fields + `["gib", , , , ]`, protocol + `[1, "gib branch"]`, keyID = the root outpoint, counterparty `anyone`, + and the git commit object inscribed on the same output. Basket `gib`, + labels `gib push` / `gib delete`, tags `origin:` / `branch:` / `commit:`. +- A push spends the previous head into the new one, so the spend chain is + the branch history. +- **Files are browsed from `head.root`, never from the repository origin.** + The repository origin resolves to the genesis tree forever. + +## Routes + +| Route | Shows | +| --- | --- | +| `/` | Recent repositories and recent pushes. | +| `/r/[origin]` | A repository: branch heads, default branch's file tree, README. | +| `/r/[origin]/tree/[ref]/[[...path]]` | A directory at a ref. | +| `/r/[origin]/blob/[ref]/[...path]` | One file: highlighted text, image, or download. | +| `/r/[origin]/commits/[...ref]` | Push history of one branch. | +| `/r/[origin]/commit/[head]` | One head: its commit, the same commit elsewhere, what builds on it. | +| `/c/[sha]` | A commit as a DAG node across every repository that publishes it. | +| `/u/[identity]` | One publisher's repositories and pushes. | +| `/me` | The connected wallet's own branches. | +| `/api/handles` | BRC-169 resolution through the server's shared cache. | +| `/manifest.json` | Web app manifest, BRC-73 grouped permissions, `babbage.trust`. | + +`[ref]` in a generated link is always a head outpoint, so links never rot. +A branch name is accepted and resolves to that branch's current head. + +## Modules + +| Module | For | +| --- | --- | +| `lib/gib-api.ts` | The overlay client and the `HeadRecord` / `RepoRecord` / `Commit` types. | +| `lib/ordfs.ts` | `/content/…` URLs, `ordfs/dir` decoding, path walking, file text. | +| `lib/gib-wallet.ts` | `mintHead`, `burnHead`, `branchFromHead`, and the token vocabulary. | +| `lib/gib-head.ts` | Decode a head from its own locking script, with no overlay. | +| `lib/resolve-ref.ts` | A URL ref → a head: outpoint, or branch name → current head. | +| `lib/handles.ts`, `lib/handles-server.ts` | BRC-169 grammar, resolution, cache, verification. | +| `lib/routes.ts` | Every internal URL. Build links here. | +| `lib/format.ts` | `txid_vout` handling, shortening, `timeAgo`. | +| `lib/stack.ts` | `STACK_URL`, `APP_URL`, `GIB_BASKET`. | + +## Running it + +```sh +bun install +bun dev # http://localhost:8266, against https://api.1sat.app +``` + +That is the whole setup: the defaults point at the live overlay and no key +or account is needed to browse. `cp .env.example .env.local` to point +`NEXT_PUBLIC_ONESAT_STACK_URL` at another 1sat-stack with the `gib` overlay +enabled. + +```sh +bun run lint && bun run typecheck && bun test && bun run build +``` + +All four must pass. CI pins bun 1.4.2 and installs `--frozen-lockfile`. +`main` auto-deploys to gibhub.net via Vercel. + +## How it ties to the other pieces + +### The overlay + +`GET {STACK_URL}/1sat/gib/…` — `/repos`, `/identity/{id}/repos`, +`/repo/{origin}`, `/repo/{origin}/branches`, +`/repo/{origin}/branch/{name}`, `/head/{outpoint}`, `/commit/{sha}`, +`/heads`. Paging is `limit` / `from` (an overlay score) / `rev`. 404 is +`null`; anything else throws. + +### ORDFS + +`GET {STACK_URL}/content/{outpoint}` or `/content/{root}/path/to/file` for +resolved file bytes — the gateway applies `ordfs/patch` chains, the site +never does. `?raw=true` gets a record's own bytes, which is how directory +manifests are read. `POST /1sat/ordfs/metadata` gets content type and +length for up to 100 outpoints at a time. + +### The wallet + +`@1sat/react`'s `useWallet()` is the only way to the wallet. Connecting +calls `getPublicKey({ identityKey: true })`. Minting and burning go through +`lib/gib-wallet.ts`, which mirrors the gib CLI's conventions exactly so a +head minted in the browser is indistinguishable from a CLI push. +`/manifest.json` declares the whole permission set as one BRC-73 grouped +request: the identity key protocol, protocol `gib branch`, basket `gib`, +labels `gib push` and `gib delete`, and a spending authorization for the +1-satoshi head plus fees. + +`/me` decodes heads from the wallet's own locking scripts +(`lib/gib-head.ts`), so it works before any indexer has caught up. + +### The gib CLI + +The Go CLI at github.com/b-open-io/gib writes the heads this site reads. +Its `internal/token` package is the reference for the token vocabulary and +its `internal/testdata/ts-fixtures.json` holds the pinned script bytes. If +this site and that package disagree, this site is wrong. + +## Rules + +- Never reimplement what `@1sat/actions` or `@1sat/templates` already do: + `dirDecode`, `pushDropLock`, `pushDropDecode`, `unlockByScript`, + `completeSignedAction`, `Inscription`. No hand-rolled PushDrop, B or + OP_RETURN scripts. +- Basket `gib`, protocol `[1, "gib branch"]`, labels `gib push` and + `gib delete` are a published interface. Renaming one voids every user's + wallet grants. +- Handles are verified per head, not per commit: the same commit reads as + verified on its author's own head and as plain text on anyone else's. +- Outpoints are `txid_vout` in this codebase; convert at the boundary with + `toOrdinalOutpoint`. + +Full detail: [../../AGENTS.md](../../AGENTS.md). From c642e0e72ea58dac7e434634d387cffc4686e4ec Mon Sep 17 00:00:00 2001 From: David Case Date: Sun, 20 Sep 2026 01:54:01 -0400 Subject: [PATCH 2/2] Declare the site's wallet permissions as one BRC-73 grouped request The site made a wallet prompt for each permission as the user reached it: identity key on connect, then the protocol, then the label, then the basket, then spending. A manifest lets the wallet ask once. /manifest.json already existed for PWA metadata and the babbage.trust block, so the permissions go into that same route rather than a new public/manifest.json: the trust block is conditional on an environment variable, so the document has to be built per request. Shape and placement follow WalletPermissionsManager in @bsv/wallet-toolbox, which is what @1sat/connect bundles. It reads `manifest.metanet || manifest.babbage` then `.groupPermissions`, and validates nothing, so three things had to be got exactly right: - Action labels are not a category. GroupedPermissions has only description, spendingAuthorization, protocolPermissions, basketAccess and certificateAccess. A label is gated as the level-1 protocol `action label `, so that is how `gib push` and `gib delete` are declared. - Level-1 entries carry no counterparty. The manager forces it to "" at level 1, and a literal "" is a reserved slot that drops the entry. - No extra keys: the grant path deep-equals granted entries against the requested ones, which are these literal objects. Declared: the identity key protocol, `gib branch`, the two action labels, basket `gib`, and a 10,000 sat monthly spending allowance. Spending is needed and not assumed: createAction computes a net spend for the 1-satoshi head plus fees and calls ensureSpendingAuthorization. Nothing else is declared; every one of those six is reached by code in lib/gib-wallet.ts or the @1sat/connect handshake. Also sets access-control-allow-origin on the response. A wallet running in a page fetches this cross-origin, and a failed fetch is cached as "no manifest" for five minutes. BSV Desktop's own manifest route does the same. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01EM5trZ4BfZpW7pBjq2onqX --- AGENTS.md | 62 +++++++++++++++++++++++++------ app/manifest.json/route.ts | 76 ++++++++++++++++++++++++++++++++++++-- skills/gibhub/SKILL.md | 12 ++++-- 3 files changed, 131 insertions(+), 19 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index fa8fd73..f6ec7e7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -263,9 +263,16 @@ verified BRC-169 handle in front of it when there is one. ## Wallet permissions `app/manifest.json/route.ts` serves the site manifest, which carries a -BRC-73 `permissions` block. A BRC-100 wallet fetches -`https://gibhub.net/manifest.json` when the app first connects and asks for -everything in it as one grouped request. +BRC-73 grouped permission block. A BRC-100 wallet fetches +`https:///manifest.json` — the origin root, nothing else — and +asks for everything in it as one grouped request instead of prompting per +call. + +The reader is `WalletPermissionsManager.fetchManifestPermissions` in +`@bsv/wallet-toolbox` (bundled into `@1sat/connect`, which is what this +site's wallets run). It reads `manifest.metanet || manifest.babbage` and +then `.groupPermissions`, and **validates nothing** — a misshapen entry is +carried into the prompt and fails later, or is silently dropped. Declare exactly what the code calls and nothing more; an over-broad manifest is worse than none. The current set is derived from @@ -273,15 +280,38 @@ manifest is worse than none. The current set is derived from | Declared | Because | | --- | --- | -| protocol `identity key retrieval`, level 1, counterparty `self` | `getPublicKey({ identityKey: true })` on connect. | -| protocol `gib branch`, level 1, counterparty `anyone` | `pushDropLock` and `unlockByScript` sign under `[1, "gib branch"]`. | +| protocol `[1, "identity key retrieval"]` | `getPublicKey({ identityKey: true })` on connect. | +| protocol `[1, "gib branch"]` | `pushDropLock` and `unlockByScript` sign under it. | +| protocol `[1, "action label gib push"]` | `mintHead`'s action label. | +| protocol `[1, "action label gib delete"]` | `burnHead`'s action label. | | basket `gib` | `listOutputs({ basket: "gib" })` on `/me`, and every minted head is filed there. | -| label `gib push` | `mintHead`. | -| label `gib delete` | `burnHead`. | -| spending authorization | `mintHead` creates a 1-satoshi output the wallet funds, and both actions pay fees. | - -`babbage.trust` is added when `NEXT_PUBLIC_TRUST_PUBLIC_KEY` is set, so a -desktop wallet can treat this origin as trusted. +| `spendingAuthorization`, 10 000 sat | `createAction` computes a net spend > 0 — a 1-satoshi head plus fees — and calls `ensureSpendingAuthorization`. A monthly allowance, counted per calendar month. | + +Three things about that list are not guessable and are easy to get wrong: + +- **Action labels are not a category.** `GroupedPermissions` has exactly + `description`, `spendingAuthorization`, `protocolPermissions`, + `basketAccess` and `certificateAccess`. The manager gates label `x` as + the level-1 protocol `action label x`, so that is how `gib push` and + `gib delete` are declared. +- **Level-1 entries carry no counterparty.** The manager forces + counterparty to `""` for level 1, so a declared one is ignored — and a + literal `""` is a reserved slot that drops the entry. Every entry here is + level 1, so none of them has a counterparty, even though `gib-wallet.ts` + signs with counterparty `anyone`. +- **No extra keys.** The grant path compares granted entries to requested + ones with a deep equality check, and the requested entries are these + literal objects. A non-spec field (`operations`, say) rides into the + prompt and can make the grant throw. + +`babbage.trust` stays under `babbage` when `NEXT_PUBLIC_TRUST_PUBLIC_KEY` +is set, because the 1Sat desktop wallet's trusted-origin check reads +`manifest.babbage.trust` directly. Permissions go under `metanet`, which is +BRC-73's canonical namespace; `babbage` is only the legacy fallback. + +A failed fetch — 404, CORS, bad JSON — is cached by the wallet as "no +manifest" for five minutes, so a broken manifest looks like no manifest +until that expires. Changing an action label, a protocol name, or the basket invalidates every user's existing grants and every user's entry in their wallet's permission @@ -330,3 +360,13 @@ not. does not prerender repository pages (they are dynamic), but `bun dev` against a stack that is down looks like a site-wide 500. Check `STACK_URL` first. + + + +# This is NOT the Next.js you know + +This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices. + +This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean. + + diff --git a/app/manifest.json/route.ts b/app/manifest.json/route.ts index e65338a..5acf722 100644 --- a/app/manifest.json/route.ts +++ b/app/manifest.json/route.ts @@ -1,10 +1,72 @@ import { APP_URL } from "@/lib/stack"; /** - * Web app manifest. When NEXT_PUBLIC_TRUST_PUBLIC_KEY is set, a - * `babbage.trust` block is included so the 1Sat desktop wallet treats this - * origin as trusted (see wallet-desktop http-server manifest trust). + * `/manifest.json` — the web app manifest, plus the two wallet-facing blocks + * a BRC-100 wallet looks for at this exact path. + * + * `metanet.groupPermissions` is BRC-73: everything the site can ask of a + * wallet, declared up front, so the wallet asks once as one grouped request + * instead of prompting per call. Shape and placement follow + * `WalletPermissionsManager.fetchManifestPermissions` in + * @bsv/wallet-toolbox, which reads `manifest.metanet || manifest.babbage` + * and then `.groupPermissions`, and validates nothing — an entry in the + * wrong shape is silently carried into the prompt. + * + * `babbage.trust`, when NEXT_PUBLIC_TRUST_PUBLIC_KEY is set, is the separate + * trusted-origin block the 1Sat desktop wallet reads (name + publicKey). + * It stays under `babbage` because that is where that reader looks. */ + +/** + * Only levels 1 and 2 are meaningful here: level 0 never prompts, so + * declaring it is a no-op. + */ +const LEVEL_1 = 1 as const; + +/** + * Action labels are not their own category in BRC-73. The permissions + * manager gates label `x` as the level-1 protocol `action label x`, so that + * is how `gib push` and `gib delete` are declared. + * + * Counterparty is deliberately absent from every entry: the manager forces + * counterparty to "" for level-1 protocols, so a declared one is ignored — + * and a literal "" is treated as a reserved slot and drops the entry. + */ +const groupPermissions = { + description: + "gibhub needs these only to publish or delete a branch from your wallet. Browsing repositories needs none of them.", + spendingAuthorization: { + // A branch head is a 1-satoshi coin; the rest is mining fees. This is + // a monthly allowance, counted by the wallet across the calendar month. + amount: 10_000, + description: "Fund the 1-satoshi branch heads you publish, and their fees", + }, + protocolPermissions: [ + { + protocolID: [LEVEL_1, "identity key retrieval"], + description: "Read your identity public key, to show your repositories", + }, + { + protocolID: [LEVEL_1, "gib branch"], + description: "Sign and unlock the branch heads you publish", + }, + { + protocolID: [LEVEL_1, "action label gib push"], + description: "Label a transaction that publishes a branch", + }, + { + protocolID: [LEVEL_1, "action label gib delete"], + description: "Label a transaction that deletes a branch", + }, + ], + basketAccess: [ + { + basket: "gib", + description: "Keep and list the branch heads you publish", + }, + ], +}; + export function GET() { const manifest: Record = { name: "gibhub", @@ -15,6 +77,7 @@ export function GET() { theme_color: "#030404", description: "Browse git repositories published on BSV with gib.", icons: [{ src: "/gibhub.svg", sizes: "any", type: "image/svg+xml" }], + metanet: { schemaVersion: 1, groupPermissions }, }; const publicKey = process.env.NEXT_PUBLIC_TRUST_PUBLIC_KEY; if (publicKey) { @@ -23,6 +86,11 @@ export function GET() { }; } return Response.json(manifest, { - headers: { "cache-control": "public, max-age=3600" }, + headers: { + "cache-control": "public, max-age=3600", + // A wallet running in a page fetches this cross-origin. The document + // is public and carries no credentials. + "access-control-allow-origin": "*", + }, }); } diff --git a/skills/gibhub/SKILL.md b/skills/gibhub/SKILL.md index 8e9b149..e6cd4c3 100644 --- a/skills/gibhub/SKILL.md +++ b/skills/gibhub/SKILL.md @@ -101,10 +101,14 @@ length for up to 100 outpoints at a time. calls `getPublicKey({ identityKey: true })`. Minting and burning go through `lib/gib-wallet.ts`, which mirrors the gib CLI's conventions exactly so a head minted in the browser is indistinguishable from a CLI push. -`/manifest.json` declares the whole permission set as one BRC-73 grouped -request: the identity key protocol, protocol `gib branch`, basket `gib`, -labels `gib push` and `gib delete`, and a spending authorization for the -1-satoshi head plus fees. +`/manifest.json` declares the whole permission set under +`metanet.groupPermissions` as one BRC-73 grouped request: protocols +`[1, "identity key retrieval"]`, `[1, "gib branch"]`, +`[1, "action label gib push"]` and `[1, "action label gib delete"]`, basket +`gib`, and a spending authorization for the 1-satoshi head plus fees. +Action labels have no category of their own — the wallet gates label `x` as +the level-1 protocol `action label x` — and level-1 entries carry no +counterparty. `/me` decodes heads from the wallet's own locking scripts (`lib/gib-head.ts`), so it works before any indexer has caught up.