Skip to content

Add just goose for one-command agent setup + fix API token auth#20

Open
baxen wants to merge 1 commit intomainfrom
baxen/goose-setup
Open

Add just goose for one-command agent setup + fix API token auth#20
baxen wants to merge 1 commit intomainfrom
baxen/goose-setup

Conversation

@baxen
Copy link
Collaborator

@baxen baxen commented Mar 10, 2026

What

One-command setup to connect a Goose agent to a local Sprout relay:

just goose

First run mints a Nostr keypair + API token and persists them to .sprout-agent.env. Subsequent runs reuse the existing identity. Drops you into a Goose session with all 16 Sprout MCP tools available.

Changes

just goose setup (3 files)

  • scripts/setup-goose-agent.sh — Idempotent script that builds sprout-admin + sprout-mcp-server if needed, mints a token with messages:read,messages:write,channels:read,channels:write scopes, and writes credentials to .sprout-agent.env (chmod 600).
  • justfile — New goose recipe that runs the setup script, sources the env, and launches goose session --with-extension with the sprout MCP server.
  • .gitignore — Added .sprout-agent.env so credentials are never committed.

API token auth fix (1 file)

  • crates/sprout-relay/src/handlers/auth.rs — The NIP-42 auth handler now intercepts sprout_ API tokens before calling AuthService::verify_auth_event. Previously, API tokens hit a dead-end Err(TokenInvalid) inside AuthService because it has no DB access by design. The fix: verify NIP-42 signature → hash token → DB lookup via Db::get_api_token_by_hash → delegate to AuthService::verify_api_token_against_hash for constant-time comparison, expiry, pubkey, and scope resolution → update last_used_at.

The auth fix is included because without it the minted token fails at connection time — the two changes are coupled.

Prerequisites

  • Docker services running (just setup)
  • Relay running (just relay)
  • Goose installed

Testing

# Verify idempotent setup
./scripts/setup-goose-agent.sh   # creates .sprout-agent.env
./scripts/setup-goose-agent.sh   # skips — already exists

# Verify MCP server connects with API token
source .sprout-agent.env
timeout 5 ./target/debug/sprout-mcp-server 2>&1
# Should print: "connected and authenticated."

# Full flow
just goose

Adds an idempotent setup script and justfile recipe so that connecting
a Goose agent to a local Sprout relay is a single command:

    just goose

What this does:
- scripts/setup-goose-agent.sh: mints a Nostr keypair + API token on
  first run, persists to .sprout-agent.env (gitignored, chmod 600).
  Subsequent runs are a no-op.
- justfile: 'just goose' sources the agent env and launches goose with
  the sprout-mcp-server extension.
- .gitignore: excludes .sprout-agent.env.

Also fixes a bug where API token authentication was not wired up in the
relay's NIP-42 auth handler. The AuthService intentionally has no DB
access, so sprout_ tokens need to be intercepted in handle_auth before
calling verify_auth_event. The handler now:
1. Extracts the auth_token tag from the NIP-42 event
2. If it starts with sprout_, hashes it, looks it up via
   Db::get_api_token_by_hash, and delegates to
   AuthService::verify_api_token_against_hash
3. Updates last_used_at on success
4. Falls through to the existing JWT/no-token paths otherwise
@baxen baxen requested a review from wesbillman as a code owner March 10, 2026 21:23
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e186c6d916

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +29 to +31
if [[ -f "${AGENT_ENV}" ]]; then
success "Agent identity already exists at .sprout-agent.env — skipping."
exit 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep building binaries when agent env already exists

Exiting immediately when .sprout-agent.env exists means subsequent just goose runs can fail after cargo clean (or any missing target/debug/sprout-mcp-server), because the setup script never reaches the build checks while the goose recipe still execs that binary. In this scenario users have a valid identity file but no executable MCP server, so the one-command flow breaks until they manually rebuild or delete the env file.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant