Add agentws worktree-management binary #4

Merged
benvin merged 2 commits from benvin/agentws into main 2026-08-15 13:13:06 +10:00
Member

Why

Agents need isolated git worktrees per branch without disturbing Ben's shared ~/src/prodenv checkouts. agentws provides that, cloning into the source-of-truth checkout so branches stay visible in the main checkout, and isolating agent work under the XDG cache.

Changes

  • Add cmd/agentws binary (own package main/newRootCmd(), mirroring agentpr) with subcommands: new, list, rm, clean, token, credential, version.
  • Add internal/agent/git.go: small, testable git helpers shelling out to the git binary (clone/fetch, worktree add/remove/list/prune, branch + config ops, porcelain parsing, branch-name sanitizing). No go-git dependency; stays CGO-free.
  • Reuse agent.GiteaToken() for auth. Tokens (~1h ephemeral) are never persisted in a remote URL or config: agentws wires itself as an ephemeral git credential helper (agentws credential get, git credential protocol on stdin, host-scoped to git.unkin.net). new sets user.name/user.email/credential.helper in the per-worktree config (via extensions.worktreeConfig) so the shared checkout's identity/config is untouched.
  • Worktrees are created FROM ~/src/prodenv/<repo> so agent branches are visible in the main checkout; rm/clean fetch there afterwards to keep the default branch current.
  • Env overrides: AGENTWS_SRC_ROOT (default ~/src/prodenv), AGENTWS_ROOT (default ~/.cache/agentws), AGENTWS_OWNER (default unkin).
  • Wire the binary into all packaging: Makefile BINARIES, scripts/build-rpm.sh, packaging/nfpm.yaml (binary + bash/zsh/fish completions), .woodpecker/release.yaml (cross-compile loop + release assets), .gitignore.
  • Document agentws in README.md and AGENTS.md.

Tests

  • Table tests for SanitizeBranch, WorktreeDirName, ParseWorktreeList.
  • A real temp git repo (bare origin + clone) exercises the worktree lifecycle: default-branch resolution, fetch, worktree add/list/remove, branch create/delete, per-worktree config isolation, source-repo resolution.
  • Hermetic cmd/agentws tests: bad input fails before any network call, and credential get stays silent for non-Gitea hosts (no token minted).
  • gofmt, go vet, go test -race ./..., make build, make completions, and make rpm all pass locally.
## Why Agents need isolated git worktrees per branch without disturbing Ben's shared `~/src/prodenv` checkouts. `agentws` provides that, cloning into the source-of-truth checkout so branches stay visible in the main checkout, and isolating agent work under the XDG cache. ## Changes - Add `cmd/agentws` binary (own `package main`/`newRootCmd()`, mirroring `agentpr`) with subcommands: `new`, `list`, `rm`, `clean`, `token`, `credential`, `version`. - Add `internal/agent/git.go`: small, testable git helpers shelling out to the `git` binary (clone/fetch, worktree add/remove/list/prune, branch + config ops, porcelain parsing, branch-name sanitizing). No go-git dependency; stays CGO-free. - Reuse `agent.GiteaToken()` for auth. Tokens (~1h ephemeral) are never persisted in a remote URL or config: `agentws` wires itself as an ephemeral git credential helper (`agentws credential get`, git credential protocol on stdin, host-scoped to git.unkin.net). `new` sets `user.name`/`user.email`/`credential.helper` in the **per-worktree** config (via `extensions.worktreeConfig`) so the shared checkout's identity/config is untouched. - Worktrees are created FROM `~/src/prodenv/<repo>` so agent branches are visible in the main checkout; `rm`/`clean` fetch there afterwards to keep the default branch current. - Env overrides: `AGENTWS_SRC_ROOT` (default ~/src/prodenv), `AGENTWS_ROOT` (default ~/.cache/agentws), `AGENTWS_OWNER` (default unkin). - Wire the binary into all packaging: `Makefile` `BINARIES`, `scripts/build-rpm.sh`, `packaging/nfpm.yaml` (binary + bash/zsh/fish completions), `.woodpecker/release.yaml` (cross-compile loop + release assets), `.gitignore`. - Document `agentws` in `README.md` and `AGENTS.md`. ## Tests - Table tests for `SanitizeBranch`, `WorktreeDirName`, `ParseWorktreeList`. - A real temp git repo (bare origin + clone) exercises the worktree lifecycle: default-branch resolution, fetch, worktree add/list/remove, branch create/delete, per-worktree config isolation, source-repo resolution. - Hermetic `cmd/agentws` tests: bad input fails before any network call, and `credential get` stays silent for non-Gitea hosts (no token minted). - `gofmt`, `go vet`, `go test -race ./...`, `make build`, `make completions`, and `make rpm` all pass locally.
unkin-agent added 1 commit 2026-08-15 12:21:47 +10:00
Add agentws worktree-management binary
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline failed
ci/woodpecker/pr/pre-commit Pipeline was successful
6a82b88947
agentws manages per-branch git worktrees for the unkin-agent user: it clones
repos into the source root (~/src/prodenv/<repo>) so branches are visible in
Ben's main checkout, and creates isolated worktrees under the worktree root
(~/.cache/agentws/<repo>__<branch>).

- New internal/agent/git.go: small, testable git helpers shelling out to the
  git binary (clone/fetch/worktree add/remove/list/prune, branch + config ops,
  porcelain parsing, path sanitizing). No go-git dependency.
- New cmd/agentws: new / list / rm / clean / token / credential subcommands.
  Auth uses an ephemeral git credential helper (agentws credential get) so the
  ~1h Gitea token is never persisted in a remote URL or config; per-worktree
  config keeps the shared checkout's identity untouched.
- Wire agentws into Makefile, scripts/build-rpm.sh, packaging/nfpm.yaml (binary
  + bash/zsh/fish completions), .woodpecker/release.yaml (cross-compile + assets)
  and .gitignore.
- Tests: table tests for parsing/sanitizing/dir-naming, a real temp-git repo for
  the worktree lifecycle, and hermetic cmd tests (bad input + credential-helper
  host guard) that never touch the network.
- Document agentws in README.md and AGENTS.md.
unkin-agent added 1 commit 2026-08-15 12:54:23 +10:00
agentws: fix golangci-lint findings
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
61e73ada51
benvin merged commit 05cc0874d6 into main 2026-08-15 13:13:06 +10:00
benvin deleted branch benvin/agentws 2026-08-15 13:13:07 +10:00
Sign in to join this conversation.