nixos/slop-cannon: Reach Gitea as the bot user
Agents pushed with a write-enabled deploy key, added to each repo by hand, and had no way to open pull requests. The bot user's token now does both: Git uses HTTPS with a credential helper that sends it, and `tea` is wrapped to log in with it. Only Dev pushes and merges to `master`. A new `my.agents.rules` option gives every agent extra instructions. `slop-cannon`'s make a pull request the default way to finish work, unless a repository's own instructions allow more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb4937f230
commit
51c26fbcec
7 files changed
+98
-52
No files matched your search
@@ -201,6 +201,9 @@ minutes for a human. See [`docs/slop-broker.md`](docs/slop-broker.md).
|
||||
- `slop build <attr>…` builds a pushed commit's flake attributes into the binary cache.
|
||||
- `slop secret keys|read|set|generate|rekey <file>` changes age secrets instead of `ragenix`.
|
||||
- `slop requests` lists your pending requests and leases.
|
||||
- Push your work to a branch and open a pull request with `tea pulls create`; only Dev merges into
|
||||
`master`. Git and `tea` use the bot user's token (see
|
||||
[`docs/sites/home/slop-cannon.md`](docs/sites/home/slop-cannon.md#gitea)).
|
||||
|
||||
## Secrets
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ See the consolidated [network assignments](../../networking.md#box-assignments)
|
||||
`untrusted`.
|
||||
- The routers keep `untrusted` to the Internet (see
|
||||
[Untrusted clients](../../networking.md#untrusted-clients)). `git.nul.ie` and
|
||||
`paseo-relay.nul.ie` resolve to colony IPv6 addresses, which are rejected, so Gitea SSH and the
|
||||
`paseo-relay.nul.ie` resolve to colony IPv6 addresses, which are rejected, so Gitea and the
|
||||
Paseo relay fall back to IPv4 immediately.
|
||||
- SSH from `hi` and `lo` works through the routers. The VM shares layer 2 with other clients
|
||||
on the `untrusted` VLAN.
|
||||
@@ -70,7 +70,7 @@ See the consolidated [network assignments](../../networking.md#box-assignments)
|
||||
- No `user-passwd.txt` (`my.user.passwordSecret = null`): root belongs to the agents, so the box
|
||||
gets no shared secrets. Recovery is through the installer ISO.
|
||||
- The VM's SSH host key is the age identity for `slop-cannon/paseo.env` and
|
||||
`slop-cannon/gitea-key`. Agents can read the host key and decrypt anything encrypted to it.
|
||||
`slop-cannon/gitea-token`. Agents can read the host key and decrypt anything encrypted to it.
|
||||
|
||||
## Paseo
|
||||
|
||||
@@ -179,20 +179,35 @@ the `slop` command (`my.agents.slop.enable`). It connects over vsock (CID 3; see
|
||||
logged in. For recovery, use the [VM serial console](../../deployment.md#vm-consoles) for
|
||||
`slop-cannon` on `palace`.
|
||||
|
||||
The VM uses a Gitea deploy key from the age secret
|
||||
`slop-cannon/gitea-key`. As `slop-cannon`, run
|
||||
`ssh-keygen -y -f /run/secrets/slop-cannon/gitea-key` to get its public key. Add that public key
|
||||
in Gitea as a write-enabled deploy key on each repo agents may use. Commits are authored as Dev
|
||||
through the shared Git config.
|
||||
|
||||
To set up provider logins and repos on a fresh agent home, connect with `ssh slop-cannon`:
|
||||
|
||||
1. `claude auth login` (a full login; `setup-token` tokens are not enough for every feature).
|
||||
2. `codex login --device-auth`.
|
||||
3. [Pair a Paseo client](#pair-a-paseo-client).
|
||||
4. `slop-clone <owner>/<repo>` for each repo. It clones a colocated jj repo into `~/src/<repo>`,
|
||||
registers it with Paseo as a local workspace, and prints the box's public key if Gitea refuses
|
||||
the clone.
|
||||
4. `slop-clone <owner>/<repo>` for each repo. It clones a colocated jj repo over HTTPS into
|
||||
`~/src/<repo>` and registers it with Paseo as a local workspace.
|
||||
|
||||
## Gitea
|
||||
|
||||
Agents reach Gitea as a bot user, with its access token (age secret `slop-cannon/gitea-token`,
|
||||
scopes `write:repository` and `write:issue`).
|
||||
|
||||
- **Git** uses HTTPS: a credential helper for `git.nul.ie` sends the token. Commits are still
|
||||
authored as Dev through the shared Git config; the pushes are the bot's.
|
||||
- **`tea`**, Gitea's CLI, is wrapped to log in with the same token, so agents can open and update
|
||||
pull requests.
|
||||
- **Pull requests:** a rule for every agent (`my.agents.rules.gitea`: a Claude rule, and part of
|
||||
Codex's `AGENTS.md`) makes a pull request from a branch of its own the default way to finish a
|
||||
piece of work, and says how with jj and `tea`. A repository's own `AGENTS.md` can allow more,
|
||||
such as pushing to its main branch.
|
||||
- **Access per repo:** where agents should only propose changes (`dev/nixfiles`, `slop-broker`),
|
||||
protect the main branch so only Dev pushes and merges. Elsewhere the bot's Write access is
|
||||
enough to push directly.
|
||||
- **Access:** the bot is a collaborator with Write on each repo agents may use. `master` on
|
||||
`dev/nixfiles` only takes pushes and merges from Dev (see
|
||||
[`slop-broker`](../../slop-broker.md#master-is-protected)).
|
||||
- **Replacing the token:** make a new one for the bot and put it in the secret with
|
||||
`ragenix -e secrets/slop-cannon/gitea-token.age`, then deploy `slop-cannon`.
|
||||
|
||||
## Pair a Paseo client
|
||||
|
||||
|
||||
+2
-2
@@ -74,8 +74,8 @@ collects garbage in that store on every run, which the roots survive until they
|
||||
### `master` is protected
|
||||
|
||||
Deploy approvals ("on the branch", the diff since `master`) and secret approvals both trust
|
||||
`master`, so only Dev may push to it: branch protection on `dev/nixfiles` in Gitea refuses pushes
|
||||
from deploy keys, including `slop-cannon`'s.
|
||||
`master`, so only Dev may push to it or merge into it: branch protection on `dev/nixfiles` in Gitea
|
||||
refuses everyone else, including the bot user that agents on `slop-cannon` push as.
|
||||
|
||||
## Approvals web app
|
||||
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
{ lib, pkgs, inputs, config, options, ... }:
|
||||
let
|
||||
inherit (lib) mkIf optional optionalAttrs;
|
||||
inherit (lib.my) mkBoolOpt';
|
||||
inherit (lib) mkIf optional optionalAttrs mapAttrs attrValues types;
|
||||
inherit (lib.my) mkOpt' mkBoolOpt';
|
||||
|
||||
cfg = config.my.agents;
|
||||
agentPkgs = inputs.llm-agents.packages.${pkgs.stdenv.hostPlatform.system};
|
||||
slopGuide = "${pkgs.slop-broker}/share/slop-broker/slop-tools.md";
|
||||
|
||||
# Claude takes a rule file each; Codex takes one `AGENTS.md`
|
||||
rules = optionalAttrs cfg.slop.enable { slop = slopGuide; }
|
||||
// mapAttrs (name: text: pkgs.writeText "${name}.md" text) cfg.rules;
|
||||
codexContext = pkgs.concatText "AGENTS.md" (attrValues rules);
|
||||
in
|
||||
{
|
||||
options.my.agents = {
|
||||
enable = mkBoolOpt' false "Whether to install and configure coding agents (Claude Code, Codex).";
|
||||
slop.enable = mkBoolOpt' false "Whether agents use the `slop` client for privileged operations.";
|
||||
rules = mkOpt' (types.attrsOf types.lines) { }
|
||||
"Instructions for every agent, by name: a Claude rule each, and appended to Codex's `AGENTS.md`.";
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
@@ -38,16 +45,14 @@ in
|
||||
};
|
||||
} // optionalAttrs (options.programs.codex ? mutableSettings) {
|
||||
mutableSettings = true;
|
||||
} // optionalAttrs cfg.slop.enable {
|
||||
context = slopGuide;
|
||||
} // optionalAttrs (rules != { }) {
|
||||
context = "${codexContext}";
|
||||
};
|
||||
|
||||
claude-code = {
|
||||
enable = true;
|
||||
package = agentPkgs.claude-code;
|
||||
rules = optionalAttrs cfg.slop.enable {
|
||||
slop = slopGuide;
|
||||
};
|
||||
inherit rules;
|
||||
settings = {
|
||||
model = "opus";
|
||||
theme = "auto";
|
||||
|
||||
@@ -32,7 +32,9 @@ in
|
||||
|
||||
agentUser = "slop-cannon";
|
||||
agentHome = "/home/${agentUser}";
|
||||
giteaKey = config.age.secrets."slop-cannon/gitea-key".path;
|
||||
# The bot user's access token, for Git over HTTPS and Gitea's API
|
||||
giteaToken = config.age.secrets."slop-cannon/gitea-token".path;
|
||||
giteaUrl = "https://git.nul.ie";
|
||||
paseoPasswordFile = config.age.secrets."slop-cannon/paseo.env".path;
|
||||
|
||||
# Steer agents to the approval broker; these match command text, so they aren't a boundary.
|
||||
@@ -44,9 +46,41 @@ in
|
||||
# The broker asks a human where policy says so; a second prompt here would only add noise
|
||||
claudeAllow = [ "Bash(slop:*)" ];
|
||||
|
||||
# Gitea takes a token as the username when the password is `x-oauth-basic`
|
||||
gitCredential = pkgs.writeShellScript "gitea-credential" ''
|
||||
[ "$1" = get ] || exit 0
|
||||
printf 'username=%s\npassword=x-oauth-basic\n' "$(cat ${giteaToken})"
|
||||
'';
|
||||
|
||||
# `tea`, logged in as the bot
|
||||
tea = pkgs.writeShellScriptBin "tea" ''
|
||||
GITEA_INSTANCE_URL=${giteaUrl} GITEA_TOKEN="$(cat ${giteaToken})" exec ${pkgs.tea}/bin/tea "$@"
|
||||
'';
|
||||
|
||||
giteaRule = ''
|
||||
# Pull requests
|
||||
|
||||
By default, your work reaches Dev as a pull request on Gitea (`${giteaUrl}`), and Dev
|
||||
merges it. The task or the repository's own instructions (its `AGENTS.md`) can say
|
||||
otherwise, for example that you may push to its main branch yourself; follow them.
|
||||
|
||||
- When a piece of work is done, push it to a branch of its own and open a pull request.
|
||||
Name the branch after the work, such as `fix-paseo-relay`.
|
||||
- Push with jj: `jj bookmark set <branch> -r <revision>` then `jj git push -b <branch>`.
|
||||
With Git: `git push origin HEAD:refs/heads/<branch>`.
|
||||
- Open the pull request with `tea`, which is already logged in, as a bot user:
|
||||
`tea pulls create --head <branch> --title "<summary>" --description "<what and why>"`.
|
||||
Pass `--head`, since a jj checkout has no current branch. Outside a clone, add
|
||||
`--repo <owner>/<repo>`.
|
||||
- To update a pull request, push to its branch again; rewriting its commits is fine.
|
||||
- Read a pull request and its comments with `tea pulls <index> --comments`, and reply with
|
||||
`tea comment <index> "<text>"`.
|
||||
- The repository's commit conventions still apply.
|
||||
'';
|
||||
|
||||
slopClone = pkgs.writeShellApplication {
|
||||
name = "slop-clone";
|
||||
runtimeInputs = with pkgs; [ jujutsu openssh paseo ];
|
||||
runtimeInputs = with pkgs; [ git jujutsu paseo ];
|
||||
text = ''
|
||||
if [ $# -ne 1 ] || [[ "$1" != */* ]]; then
|
||||
echo "usage: slop-clone <owner>/<repo>" >&2
|
||||
@@ -55,10 +89,9 @@ in
|
||||
repo="$1"
|
||||
dest="$HOME/src/''${repo##*/}"
|
||||
|
||||
if ! jj git clone --colocate "git@git.nul.ie:$repo.git" "$dest"; then
|
||||
if ! jj git clone --colocate "${giteaUrl}/$repo.git" "$dest"; then
|
||||
echo >&2
|
||||
echo "Clone failed. If Gitea refused the key, add it as a write-enabled deploy key on $repo:" >&2
|
||||
ssh-keygen -y -f ${giteaKey} >&2
|
||||
echo "Clone failed. If Gitea refused, add the bot user to $repo as a collaborator with Write." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -158,7 +191,7 @@ in
|
||||
secrets = {
|
||||
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBCkgBZh/YejY+gDnGa9r5SPo1+aHWPAAAIfENE7t0Om";
|
||||
files = {
|
||||
"slop-cannon/gitea-key".owner = agentUser;
|
||||
"slop-cannon/gitea-token".owner = agentUser;
|
||||
# `PASEO_PASSWORD=...`
|
||||
"slop-cannon/paseo.env" = { };
|
||||
};
|
||||
@@ -192,9 +225,10 @@ in
|
||||
my.agents = {
|
||||
enable = true;
|
||||
slop.enable = true;
|
||||
rules.gitea = giteaRule;
|
||||
};
|
||||
|
||||
home.packages = [ slopClone slopPair ];
|
||||
home.packages = [ slopClone slopPair tea ];
|
||||
|
||||
programs = {
|
||||
# Permissive by default: the VM is the boundary, and `slop-broker` gates what needs
|
||||
@@ -210,10 +244,7 @@ in
|
||||
sandbox_mode = "danger-full-access";
|
||||
};
|
||||
|
||||
# The shared config pins `IdentityFile` for every host
|
||||
ssh.settings."git.nul.ie" = {
|
||||
IdentityFile = [ giteaKey ];
|
||||
};
|
||||
git.settings.credential.${giteaUrl}.helper = "${gitCredential}";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IFVTM044ZyBLdi8z
|
||||
ZG1EM0Jxekp6NklwalZ6M2VSQnhFdHpnbkNXVFgwZ3JhWUlnaFRBCjErOStpemNS
|
||||
aEpsczF6QkVEenEvRXVQKzZmdU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qeoq9B63cdUIc4edzpYZnz4/
|
||||
BjOFUwpMSQo4Wa/OI6aRLsEI
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
@@ -0,0 +1,13 @@
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IFVTM044ZyBlcGFh
|
||||
Y3AyZ1hkM0VZZXdXWE5oQzZoNzc5TTVmSGR1NXBWcEZPblViK2gwCjZPbm82TUh4
|
||||
WXJ6OVFJTThxWWhpL3BvOVNJbzV4aDEzSXYwcWd5QVhiMmsKLT4gWDI1NTE5IFhS
|
||||
YUNBelpJRCtXd1ZBdFJhcE54QnJzMG1KamFwNTRMSE0rbkxpYWYybncKTlBIRldr
|
||||
MlVEZEJONVBwR0VhY09iN25WbnRXa1JIK21uU0tPaERCbyswYwotPiBYMjU1MTkg
|
||||
eHJVN0xwVHl3U3FweGN3N1pEK3NGS0J1NXc1UktnTFozK25JYWUyaG9DSQprRDZS
|
||||
amJHMytWYWtVU0IzekdGNVpsL0RkVU9hVVFJaVc0ZEVuZUl6QzE4Ci0+IEItZ3Jl
|
||||
YXNlCi9neGpYVXRmWk5PQm1lVWRMbEhyc1JvOWdOTXRXY29RZ1BHdTlaMHU3VUxY
|
||||
NGcKLS0tIE9tZUVzWXJqb25zdVFPOEVuZjZGWWFJQXZuZ2ptMEhFOFd6UEQ4NkRp
|
||||
SEUKvQwmW4yANCv/vpZCSppsebkdlgAmjaYLRpE5XIKMyMU6JeHSDVGla1B2q5mw
|
||||
DwiCemMGM1sC1eYAX8D5jhiONn0ycQi/JEaI8Q==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
Reference in new issue
Block a user