5.7 KiB
5.7 KiB
Source subagent brief
Template. Replace <...>, drop the blocks that do not apply to the profile, append the shared rules from conventions.md.
Work in <source path> (<language/toolchain>, <"a fork of <upstream>" or "Bryan's own project">; read AGENTS.md / CLAUDE.md / README first). Branch <branch> has <N> local commits on top of <base ref> (<"upstream/main, already fetched, 0 behind" | "the last released tag <tag>" | "origin/main">):
<git log --format='%h %s' <base>..HEAD>
Goal 1, history: rewrite these into clear, single-purpose commits on top of <base>: one commit per feature / bugfix / docs / chore / test. A commit whose subject joins two things with "and" should be split if the parts are separable; a commit that sneaks unrelated changes (a fix to an earlier feature, a docs update, UI tweaks inside a routing commit) should have those parts moved to their own commit or folded into the commit they belong to. Each commit must build on its own (build + vet of touched packages at each commit; full test suite at the end). Use judgement; don't split for the sake of splitting. If the history is already clean, keep it and say so.
Constraints for the rewrite:
- The final tree MUST be byte-identical to the current HEAD <sha> tree (`git diff <sha> HEAD` empty), except for the additions requested below and real bug fixes, each as its own commit, reported.
- First create a backup ref: `git branch backup/pre-rewrite <sha>`. Leave it.
- Non-interactive git only (no rebase -i): e.g. `git checkout -b work <base>`, recreate commits with `git checkout <sha> -- <paths>` / `git apply` of partial diffs, then move <branch> to the result.
- Ignored dirs that hold tracked files (e.g. docs/) need `git add -f`.
- Known flaky tests to ignore only if they fail under load and pass on rerun: <list or "none known">.
Profile full: native build and install (add to the brief)
Goal 2, standalone: the source must run without Docker on linux amd64 and arm64. Add, as separate single-purpose commits after the rewritten history (e.g. `build: add makefile for native build and install`, `feat: add systemd unit`, `docs: document native install`):
1. A root `makefile` if none exists (check first; reuse and extend an existing one instead), targets at least:
- default `all`/`build`: native build with the host toolchain, static where possible (Go: CGO_ENABLED=0 if the project builds and works without cgo), version metadata injected (Go: -ldflags -X for Version/Commit/BuildDate from git describe / rev-parse / date), output ./<binary>;
- `build-amd64`, `build-arm64` (GOOS=linux GOARCH=...);
- `install`: binary to $(PREFIX)/bin (PREFIX=/usr/local, DESTDIR supported), systemd unit to /etc/systemd/system, example config to /etc/<name>/ only if not already present, state dir created, then `systemctl daemon-reload`;
- `uninstall`, `test`, `debug` (unoptimized build with debug info, document it), `clean`, plus whatever the project needs.
Privileges for install/uninstall: when not root (id -u != 0) run the privileged commands through `sudo`; if sudo is missing or fails (no password given), the target fails with a clear error. No sudo when already root.
2. A ready-to-copy systemd unit in the repo (e.g. packaging/systemd/<name>.service) running the installed binary with its config in /etc/<name>/, state in /var/lib/<name> (set paths explicitly in the example config so nothing depends on HOME), Restart=on-failure, hardening (DynamicUser or a dedicated user, StateDirectory=, ConfigurationDirectory=, NoNewPrivileges, ProtectSystem=strict, ReadWritePaths for every path the program writes, including the config file if the program rewrites it). Verify the binary works under those constraints.
3. Document make targets and the systemd install in the project docs and briefly in README.
Test in Docker only: `make`, `make build-arm64` (check with `file` it is aarch64), `make test`; `make install` in a throwaway container as root and as a non-root user without sudo (must fail clearly); `systemd-analyze verify` the unit in a container, or boot it in a systemd-enabled container if feasible.
Profile container: image built by the source repo (add to the brief)
Goal 2, image: the source repo owns its image (reference: source/coredns-web-ui). Verify, and add as separate commits only what is missing:
- a lowercase `dockerfile` with a test target and a minimal runtime (scratch or distroless, non-root), multi-arch by cross-compilation (FROM --platform=$BUILDPLATFORM, GOARCH=$TARGETARCH), version metadata from build args;
- `.gitea/workflows/test.yaml` (push on main) and `.gitea/workflows/image.yaml` (on tag push: validate the tag is semver equal to the version, build linux/amd64 + linux/arm64 with buildx, smoke test the amd64 image, push `${GIT_HOST}/source/<name>:<version>` and `latest` for non-prerelease tags).
Test locally in Docker: build both platforms, check the arm64 binary is aarch64, run the amd64 image and hit <health endpoint> (expect 200).
Profile bin: release binaries only (add to the brief)
Goal 2, release: check the release workflow in .gitea/workflows (reference: source/goreflex release.yml) produces the expected artifacts on tag push for version <version>; fix it in its own `ci:` commit if needed. Run the project's own build/test targets in Docker.
Closing block (all profiles)
After the commits: create an annotated tag `<version>` (no v prefix, message "<name> <version>") on the final HEAD; no other tags. Ensure remote `origin` = https://git.bjphoster.com/source/<name>.git exists locally (add it if missing; keep `upstream` if present).
Report: final commit list (hash + subject + one line on contents), the tag SHA, confirmation that `git diff <sha> HEAD` is empty apart from the listed additions/fixes, test results.