giteabot backport / giteabot (push) Skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Canceled after 0s
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Canceled after 0s
release-nightly / nightly-binary (push) Canceled after 0s
release-nightly / nightly-container (push) Canceled after 0s
IsBranchExist and IsTagExist now ask got.RefExists instead of git's cat-file batch. got's exit status is useless here: `got ref -l <unknown>` exits 0 with no output, and an empty repository reports "HEAD: refs/heads/main" for a branch that does not exist yet. The wrapper therefore parses the "<name>: <value>" line and follows symbolic entries with a bounded depth. IsReferenceExist/IsObjectExist keep the cat-file batch: they answer "is this object present" for bare and short commit IDs, which got ref cannot, and `got cat` resolves unknown arguments as paths in HEAD's tree, so it would report file names as existing objects. That gap is documented, not silent. Verified: go test ./modules/got ./modules/git (ref_test.go covers both ref behaviours, the empty repository, and the enclosing-repository escape; ref_got_test.go covers true/false branches and tags plus a missing got binary). Full go test ./modules/... ./services/... ./models/... ./routers/... and make -C cgi check pass. Assisted-by: splinter:claude-opus-4
227 lines
13 KiB
Markdown
227 lines
13 KiB
Markdown
# gotea — AGENTS.md
|
|
|
|
Gotea is a fork of Gitea. The repository backend is moving from `git` to
|
|
[got](https://got.gameoftrees.org/) (Game of Trees), and the old-browser frontend
|
|
is a C99/POSIX CGI program serving HTML 4.01 with a CDE/Motif look. The Go forge
|
|
backend remains the source of truth for accounts, permissions, issues, API, and
|
|
storage.
|
|
|
|
## Current state
|
|
|
|
- Base: upstream Gitea v28.4.0, full history, `upstream` remote kept.
|
|
- Remote: `origin` = `https://git.kropa.tech/hiddenbox/gotea`. This is the only
|
|
remote to push to; `git.hiddenbox.org` and the 192.168.1.148 SSH host are not
|
|
gotea's remotes. `upstream` is fetch-only reference to Gitea, never push.
|
|
- Main module `gotea.dev`; binary `gotea`. Identity strings and the English locale
|
|
are renamed; upstream copyright notices stay.
|
|
- The Go backend still calls `modules/git` for most operations. Bare repository
|
|
creation, `IsEmpty`, `GetDefaultBranch`, `SetDefaultBranch`,
|
|
`GetBranchCommitID`, and `GetBranchNames` now go through `modules/got`; the rest
|
|
of the migration is open.
|
|
- `cgi/gotea-cgi` is the read-only old-browser frontend. It browses bare
|
|
repositories with `got`; it does not authenticate and has no write path.
|
|
- Gotea Pages is a prototype: a `pages` branch is checked out with got, built
|
|
with the vendored `bb` at `third_party/bb`, and served from a separate host.
|
|
|
|
## Architecture rules
|
|
|
|
- **Do not rewrite the forge backend in C up front.** Authentication, permissions,
|
|
issues, pull requests, API, and migrations live in Go for good reasons. The C CGI
|
|
is a presentation tier over the same repositories and can take over UI features
|
|
incrementally.
|
|
- The CGI must not call Gotea over HTTP or read its database yet. Its contract is
|
|
`GOTEA_REPO_ROOT` plus `got`; keep it that way until an auth design exists.
|
|
- Keep the two tiers separable: the CGI must build and run with only libc, POSIX,
|
|
and `got`.
|
|
|
|
## Hard rules
|
|
|
|
- **Brand:** new code, UI strings, docs, and paths use *gotea* / *Gotea*, never
|
|
*gitea* / *Gitea*. Upstream attribution and compatibility names are exceptions.
|
|
- **Never blind-replace `git` with `got`.** Keep `git-lfs`, `.git`, `.gitignore`,
|
|
Git wire-protocol names, `github.com` URLs, and the fact that gotea stores
|
|
standard Git-format repositories. got is the engine, not a new object format.
|
|
- **Compatibility renames need an alias or migration, not `sed`:** `GITEA_*` env
|
|
overrides, `app.ini` keys, DB table/column prefixes, dump formats, and API JSON
|
|
fields are consumed by users and tooling.
|
|
- **No new direct `git` subprocesses in runtime code.** New or modified VCS code
|
|
goes through one got wrapper (`modules/got`). The existing `modules/git` calls are
|
|
migration debt, not a pattern to copy.
|
|
- If got genuinely cannot do an operation, stop and record the gap plus a proposed
|
|
design. Do not silently add a `git` fallback.
|
|
- **Copyright:** keep upstream Gitea/MIT notices intact. New Go files get
|
|
`// Copyright <year> The Gotea Authors.` and `// SPDX-License-Identifier: MIT`.
|
|
New C files use the same SPDX header in C comment form.
|
|
- **CGI security:** HTML-escape every repository string; never invoke a shell;
|
|
validate repository names and reject `..`; treat `GOTEA_REPO_ROOT` as public
|
|
data. Private-repository access needs an auth layer first.
|
|
|
|
## Frontend rules (cgi/)
|
|
|
|
- HTML 4.01 Transitional. No JavaScript, no `<script>`, no `javascript:` URLs,
|
|
no external fonts, CSS frameworks, or images required for layout.
|
|
- CSS1 is the ceiling. Prefer table layout and `bgcolor`/`<font>` fallbacks so a
|
|
pre-CSS browser still gets a usable page. Do not use flexbox, grid, CSS
|
|
variables, or rounded corners.
|
|
- The look is CDE/Motif: grey base, bevelled in/out borders, navy title bars, a
|
|
Front Panel sidebar. Colours come from the palette, not hard-coded literals.
|
|
`GOTEA_PALETTE` accepts key=value themes and eight-slot CDE `.dp` files.
|
|
- C99 + POSIX only (`-D_POSIX_C_SOURCE=200809L`), no third-party libraries.
|
|
Build with `-Wall -Wextra -Wpedantic -Werror`.
|
|
- Keep `make -C cgi check` green. Tests may use `git` only to create fixtures.
|
|
- The CGI's only navigation state is `?ref=`; validate it like a revision (no
|
|
`..`, no leading dash) and preserve it in repository links.
|
|
- `tidy -q -e` must accept generated pages; add table `summary` attributes rather
|
|
than suppressing warnings.
|
|
|
|
## Build and test
|
|
|
|
```sh
|
|
make gotea # Go backend binary
|
|
make build # full Gitea build (frontend needs pnpm/Node)
|
|
make -C cgi # CGI binary
|
|
make -C cgi check # CGI + pages tests, including a real bb build
|
|
make bb # vendored bb static site generator
|
|
make fmt # after .go edits
|
|
make tidy # after go.mod edits
|
|
make lint # or lint-backend / lint-frontend
|
|
make test-backend # single: make test-backend#TestName
|
|
make test-integration # needs git-lfs; SQLite default
|
|
make test-e2e # single: GITEA_TEST_E2E_FLAGS='<file>' make test-e2e
|
|
make generate-swagger # after API changes; verify with make swagger-check
|
|
make test-migration # after modelmigration changes
|
|
```
|
|
|
|
- Focused Go test: `go test -run '^TestName$' ./path/to/package/`.
|
|
- got tests: `go test ./modules/got`; init wiring:
|
|
`go test ./modules/git -run 'TestInitRepositoryLocalBare'`.
|
|
- Raise `ulimit -n 12288` before `make watch`.
|
|
- The backend binary is `gotea`; run it from the repository root with
|
|
`./gotea web`.
|
|
|
|
## got integration
|
|
|
|
- Put every got invocation in `modules/got` (replacing `modules/git`). Nothing else
|
|
execs got or parses repository internals. Bare init, empty state, default-branch
|
|
read/write, branch ID lookup, and branch listing are already there; non-bare temp
|
|
worktrees still use git and must be migrated deliberately.
|
|
- `[git] GOT_PATH` selects the got binary (default `got`).
|
|
- `SetDefaultBranch` uses `got ref -s` for existing branches and writes HEAD
|
|
atomically for unborn branches, because `got ref -s` requires the target to exist.
|
|
- `run` validates every `-r` target before calling got. got searches upwards, so a
|
|
path that is not a repository would otherwise answer with an enclosing one - a
|
|
wrong answer, not an error. The same hook recreates `objects/pack` and `refs/`
|
|
when a checkout dropped those empty directories, because got refuses such a repo.
|
|
- `Branches` lists names from `got ref -l refs/heads/`, never `got branch -l`: the
|
|
latter also reports `refs/remotes/` copies and can repeat a name. It takes the
|
|
order from `got branch -lt` and appends any name that pass missed, so a failure
|
|
there degrades to the lexical order instead of failing the listing.
|
|
- `RefExists` is the branch/tag existence check. got's exit status cannot be used
|
|
for it: `got ref -l <unknown>` exits 0 with no output, and in an empty
|
|
repository it lists `HEAD: refs/heads/<default>` for a branch that does not
|
|
exist yet. The wrapper parses the `<name>: <value>` line, follows symbolic
|
|
entries (bounded), and answers true only for an object ID.
|
|
- `IsReferenceExist`/`IsObjectExist` still use git's cat-file batch on purpose:
|
|
they answer "is this object here" (commit IDs, short hashes), which `got ref`
|
|
cannot. Do not swap them for `RefExists`; a bare object ID must stay false
|
|
there. This is a known gap, not an oversight - got has no object-existence
|
|
command, and `got cat` resolves non-object arguments as paths in HEAD's tree,
|
|
so it reports files as existing objects.
|
|
- File changes require a **work tree**, whose metadata is `.got/` (not `.git/`).
|
|
A bare repository cannot be edited in place: server-side edits and merges need a
|
|
temporary `got checkout` work tree and a `got commit`. Serialize per repository
|
|
and clean up.
|
|
- A temporary `got checkout` leaves `refs/got/worktree/base-<uuid>` in the
|
|
repository. Delete it with `got ref -d` when removing the worktree, or refs
|
|
accumulate and block object cleanup. `cgi/pages/publish.sh` does this.
|
|
- Commits take their author from `GOT_AUTHOR` (or `got.conf`/Git config). Gitea's
|
|
`GIT_AUTHOR_*` variables are ignored by got; pass `GOT_AUTHOR` per command rather
|
|
than mutating shared repository config.
|
|
- Transports: `got clone`/`got fetch` speak smart HTTP(S), but **`got send` is
|
|
SSH-only**. `gotd` is a Unix-socket daemon behind `gotsh`/SSH with no HTTP
|
|
listener; `gotwebd` is a read-only web UI. got therefore cannot serve HTTP
|
|
`git push`. Settle the transport design before rewriting push and HTTP handlers.
|
|
- Maintenance is `gotadmin`: `init`, `pack`, `cleanup` (there is no `git gc`),
|
|
`info`, `dump`, `load`. got has no fast-export/fast-import equivalent, so mirrors,
|
|
imports, and exports that relied on them need a new design.
|
|
- got writes remotes to `.got/got.conf` as well as `.git/config`; keep both in sync
|
|
when gotea changes a remote.
|
|
- got has no documented Git-hook support; assume hooks do not run and invoke
|
|
pre-receive/update-style hooks from gotea itself.
|
|
- `gotd` cannot serve SHA-256 repositories. Keep SHA-1 until the whole serving path
|
|
supports it.
|
|
- Pin the minimum got version and test against it: got is pre-1.0 and flags drift
|
|
(0.126 is current in Debian testing; 0.111 is in trixie).
|
|
- Wikis are repositories too; route them through the same got wrapper.
|
|
|
|
## Gotea Pages
|
|
|
|
- A `pages` branch is a bb project. `cgi/pages/publish.sh` checks it out with
|
|
`got`, runs `third_party/bb/bb build`, and swaps `dist/` into
|
|
`GOTEA_PAGES_ROOT/<owner>/<repo>/` atomically.
|
|
- The push path is `cgi/pages/install-hook.sh` -> `hooks/post-receive.d/gotea-pages`
|
|
-> `publish.sh`. Keep the hook non-fatal by default; `GOTEA_PAGES_STRICT=1`
|
|
makes publish failures fail the push.
|
|
- **Never serve user HTML on the main app origin.** Pages content is
|
|
attacker-controlled; same-origin means stored XSS against sessions and CSRF
|
|
tokens. Serve only when `GOTEA_PAGES_HOST` matches `HTTP_HOST`, with
|
|
`X-Content-Type-Options: nosniff` and `realpath` containment under
|
|
`GOTEA_PAGES_ROOT/<owner>/<repo>`.
|
|
- Pages inherit repository visibility: a private repository's site must not be
|
|
readable anonymously, even via a guessed URL. The current publisher has no
|
|
visibility check, so only public repos may be allowlisted.
|
|
- `GOTEA_PAGES_ALLOW` is the serving allowlist; `install-hook.sh` appends the
|
|
repo to it. Do not serve a built tree that is not in it.
|
|
- Publishing must be atomic and idempotent: stage aside, swap in, keep the last
|
|
good version when a build or swap fails.
|
|
- bb is vendored under `third_party/bb`; do not shell out to a system bb or edit
|
|
the vendored copy in place. Update it from upstream deliberately and keep
|
|
`third_party/bb/NOTICE` current.
|
|
|
|
## Layout
|
|
|
|
- Backend: `routers/` (HTTP), `services/` (logic), `models/` + `modelmigration/`
|
|
(DB), `modules/` (infrastructure), `templates/`.
|
|
- Backend VCS: `modules/got` for migrated got calls; `modules/git` is the
|
|
remaining git surface.
|
|
- Frontend: `web_src/` (Vue + Vite) for the Gitea UI; `cgi/` for the HTML 4.01
|
|
frontend; `cgi/pages/` for publish/hook scripts.
|
|
- Vendored: `third_party/bb` (MIT static site generator).
|
|
- Tests: `*_test.go` beside code, `tests/integration/`, `_mock_data/` recordings;
|
|
CGI and pages tests in `cgi/tests/`.
|
|
- In `options/locale`, edit only `locale_en-US.json`; other locales are synced
|
|
automatically.
|
|
|
|
## Repository conventions
|
|
|
|
- Never assume; verify before claiming. List targets with `make help`.
|
|
- Read relevant developer documentation in `docs/`.
|
|
- PR descriptions: minimal, what and why, no task or file listings. Screenshots for
|
|
UI changes, before and after when modifying existing UI, under 1000 characters.
|
|
- Reference issues and PRs by full URL, not number.
|
|
- Conventional Commits for commit messages and PR titles, plus Gitea's `enhance`
|
|
type for user-facing enhancements.
|
|
- Add `Assisted-by: AGENT_NAME:MODEL_VERSION` to commit messages; never
|
|
`Co-Authored-By` or `Signed-off-by`.
|
|
- Attribute agent authorship on one trailing line in issue/PR comments, not as a
|
|
description section.
|
|
- Never rewrite history unless asked; update PRs with new commits and normal push.
|
|
- Comments: almost none, short, explaining why. Never narrate the code or prompt.
|
|
- In TypeScript use `!` instead of `?.`/`??` when a value always exists.
|
|
- In Go prefer modern language features; write sizes as `64 * 1024`, not `64 << 10`.
|
|
- For the Vue UI prefer `tw-*` utilities over inline styles; this does not apply to
|
|
`cgi/`, which stays CSS1/tables.
|
|
- Run `make fmt` after `.go` edits, `make tidy` after `go.mod` edits, and lint what
|
|
changed with `make lint-go`, `lint-js`, `lint-css`, or `lint-templates`.
|
|
- Fix the cause rather than disabling a linter or weakening a test. If unavoidable,
|
|
use the narrowest scope with a trailing reason comment.
|
|
- Write the fewest, fastest tests covering the behaviour. Aim for sub-2s integration
|
|
and sub-4s e2e tests; wait on deterministic conditions, not sleeps.
|
|
|
|
## Before calling work done
|
|
|
|
`make fmt`, `make -C cgi check`, `tidy -q -e` on generated HTML, and the relevant
|
|
test target must pass. Check that new runtime code does not add
|
|
`exec.Command("git"` (or `exec.CommandContext`) outside `modules/git`, tests, and
|
|
explicit compatibility shims.
|