You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix(mcp): auth-aware gateway MCP, stderr for Execute, login reauth
- Skip requireGatewayProject for gateway mcp when no API key; enforce when key present
- Route gateway mcp errors and login-required messages to stderr; no interactive login
- argvContainsGatewayMCP skips global flags (e.g. --profile, -p)
- Always register hookdeck_login with optional reauth; clear credentials then device login
- Hedged list-projects failure hint suggesting reauth for 401/403-style errors
- ClearMCPProfileCredentials for memory-only or persisted config
- Acceptance: subprocess gateway mcp with stdin pipe; stdout JSON-RPC hygiene
Made-with: Cursor
* refactor(config): centralize silent credential clear for logout and MCP
- Rename ClearMCPProfileCredentials to ClearActiveProfileCredentials; document disk vs memory paths
- Logout uses the same helper as MCP reauth; zeroProfileCredentialFields helper
- RemoveAllProfiles clears in-memory credential fields after wiping the file (parity with logout -a)
- Rename config test to match new API
Made-with: Cursor
* Tighten error matching, improve login context handling, and tests (#281)
* fix(review): tighten error matching, add safety comments, revert noise
- tool_projects_errors.go: match "status code: 4xx" instead of bare
"401"/"403" to avoid false positives on IDs or timestamps
- tool_login.go: remove `_ = ctx` suppression, add TODO for context
propagation to polling goroutine, document happens-before on
loginState.err via channel close
- root.go: add maintenance comment linking flagNeedsNextArg to init()
- helpers.go: revert unrelated Attempt struct alignment change
https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
* fix(review): ListProjects returns *APIError, add reauth + argv tests
- projects.go: use checkAndPrintError instead of manual status check so
ListProjects errors are structured *APIError — the errors.As path in
shouldSuggestReauthAfterListProjectsFailure now matches directly
- tool_projects_errors_test.go: unit tests for reauth hint logic covering
APIError 401/403, plain error fallback, and false-positive resistance
- root_argv_test.go: document boolean-flag-between-subcommands limitation
https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
* fix(mcp): cancel login polling goroutine on MCP session close
Thread the request context into the login polling goroutine so it
stops promptly when the MCP transport closes, instead of running for
up to ~4 minutes after the client disconnects.
WaitForAPIKey blocks with time.Sleep and doesn't accept a context, so
we run it in an inner goroutine and select on both its result channel
and ctx.Done(). The inner goroutine is bounded by loginMaxAttempts.
https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
---------
Co-authored-by: Claude <noreply@anthropic.com>
* fix(mcp): review fixes for auth-aware gateway MCP (#282)
* fix(review): tighten error matching, add safety comments, revert noise
- tool_projects_errors.go: match "status code: 4xx" instead of bare
"401"/"403" to avoid false positives on IDs or timestamps
- tool_login.go: remove `_ = ctx` suppression, add TODO for context
propagation to polling goroutine, document happens-before on
loginState.err via channel close
- root.go: add maintenance comment linking flagNeedsNextArg to init()
- helpers.go: revert unrelated Attempt struct alignment change
https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
* fix(mcp): cancel login polling goroutine on MCP session close
Thread the request context into the login polling goroutine so it
stops promptly when the MCP transport closes, instead of running for
up to ~4 minutes after the client disconnects.
WaitForAPIKey blocks with time.Sleep and doesn't accept a context, so
we run it in an inner goroutine and select on both its result channel
and ctx.Done(). The inner goroutine is bounded by loginMaxAttempts.
https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
* fix(mcp): use session-level context for login polling, not per-request
The per-request ctx passed to MCP tool handlers is cancelled when the
handler returns. The previous commit selected on that ctx in the login
polling goroutine, which killed the poll immediately after returning
the browser URL — breaking in-MCP authentication.
Fix: add a sessionCtx field to Server, set it in Run() (called by
RunStdio and tests), and select on that instead. The session context
is only cancelled when the MCP transport closes (stdin EOF), which is
the correct signal to abandon login polling.
Also adds TestLoginTool_PollSurvivesAcrossToolCalls: a regression test
that starts a login flow, lets the mock auth complete between tool
calls, and verifies the client is authenticated on the second call.
This would have caught the per-request ctx bug.
https://claude.ai/code/session_01EpXZqTmgybtjgmSALukH8d
---------
Co-authored-by: Claude <noreply@anthropic.com>
* fix(test): MCP login poll timing, profile save guard, retry API 500
- Wait loginPollInterval before second hookdeck_login in PollSurvives test
- SaveActiveProfileAfterLogin: skip disk persist when viper nil (tests)
- CLIRunner: retry transient HTTP 500 like 502 for acceptance flakes
Made-with: Cursor
* fix(cli): validate without stale project headers; sync profile from API
Omit X-Team-ID/X-Project-ID on GET /cli-auth/validate via clientForCLIAuthValidate
so a valid CLI key is not rejected when config.toml has a stale project_id.
After successful validate on the existing-key login path, persist project_id,
project_mode, and project_type from the response.
Add Profile Apply* helpers for validate, poll, and CI responses; use them from
login, interactive login, and MCP hookdeck_login. requireGatewayProject now
applies the full validate response (including project_id) without clearing
guest_url.
Tests: auth validate headers, profile apply helpers, LoadConfigFromFile,
gateway resolve-from-validate integration.
Made-with: Cursor
* docs(agents): go test in Cursor, module cache, out-of-sandbox runs
Document GOMODCACHE for agent shells, prompt-first elevated execution, and
point CLAUDE.md at AGENTS.md as the single source for agent instructions.
Made-with: Cursor
* chore: send command flag names in CLI telemetry
Include changed flag names (not values) as command_flags in
X-Hookdeck-CLI-Telemetry JSON. Wire CollectChangedFlagNames from root
initTelemetry. Add unit tests and acceptance test for login --api-key
and --cli-key over the recording proxy.
Made-with: Cursor
---------
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: AGENTS.md
+57-8Lines changed: 57 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -228,12 +228,21 @@ pkg/hookdeck/
228
228
229
229
## 5. Development Workflow
230
230
231
+
### Agent command execution (Cursor / AI)
232
+
233
+
**Strong preference:** When a command needs more than the default sandbox (network, full filesystem, real module cache, TLS to external services, `gpg-agent`, etc.), **prompt the user for permission to run that command outside the sandbox** (e.g. approve **`required_permissions: ["all"]`**, **network**, or the product’s “run outside sandbox” control)—and **execute it yourself** after approval.
234
+
235
+
- **Do not** default to “please run this in your terminal” or long copy-paste-only instructions when the environment can elevate the **same** command.
236
+
- **Do** use copy-paste or “run locally” guidance only when elevation is **refused**, **unavailable**, or the user explicitly prefers it.
237
+
238
+
This applies to **`go test`**, **`go mod download`**, **`git`**, **`gh`**, builds, and acceptance tests—not only network calls.
239
+
231
240
### Building and Testing
232
241
```bash
233
242
# Build the CLI
234
243
go build -o hookdeck cmd/hookdeck/main.go
235
244
236
-
# Run tests
245
+
# Run all unit tests (default packages; run from repo root)
237
246
go test ./...
238
247
239
248
# Run specific package tests
@@ -243,17 +252,55 @@ go test ./pkg/cmd/
243
252
go test -race ./...
244
253
```
245
254
255
+
### Running `go test` after code changes (required for agents)
256
+
257
+
**Whenever you change Go code in this repo, run tests from the repository root** and treat the run as failed if compilation or any test fails.
258
+
259
+
**Recommended commandin Cursor (module cache + full permissions):**
260
+
261
+
```bash
262
+
cd /path/to/hookdeck-cli # repo root containing go.mod
263
+
GOMODCACHE="$(go env GOPATH)/pkg/mod" go test ./...
264
+
```
265
+
266
+
**Prompt the user** to approve running that command**outside the sandbox** with **`required_permissions: ["all"]`** and **`["network"]`** when the module cache may need to fetch (first run or new dependencies). Plain `go test ./...` is fine on a normal developer machine where `GOMODCACHE` is unset or already populated.
267
+
268
+
**Cursor / agent environments — prompt for out-of-sandbox, fix module cache, do not skip tests**
269
+
270
+
1. **Prompt the user**for permission, then run `go test ./...` with **`required_permissions: ["all"]`** (disable sandbox for that command). Do **not** use the default sandbox for`go test` here.
271
+
272
+
2. **If you still see `no required module provides package github.com/...`**, the shell often has **`GOMODCACHE`**set to an **empty** Cursor temp directory (even with `all`). That is **not** a broken `go.mod`. **Re-run tests with an explicit cache path** (pick one):
273
+
274
+
```bash
275
+
GOMODCACHE="$(go env GOPATH)/pkg/mod" go mod download
276
+
GOMODCACHE="$(go env GOPATH)/pkg/mod" go test ./...
277
+
```
278
+
279
+
Or unset the variable so Go uses its default (`$GOPATH/pkg/mod`):
280
+
281
+
```bash
282
+
env -u GOMODCACHE go mod download
283
+
env -u GOMODCACHE go test ./...
284
+
```
285
+
286
+
Use **`go mod download`** with **`required_permissions: ["network"]` or `["all"]`** the first time the cache is cold (after **prompting**for that permission).
287
+
288
+
- **`["network"]` alone is often not enough**for`go test` because compilation still needs a **readable** module cache.
289
+
- **Prompt for out-of-sandbox / full permissions**, then re-run with **`["all"]`** and the **`GOMODCACHE`** / **`env -u`** fix above—**do not** skip tests or push the user to run commands manually unless they decline elevation.
290
+
291
+
**Acceptance tests** live under `test/acceptance/` with **build tags** (they are **not** included in plain `go test ./...`). See **`test/acceptance/README.md`**for tags, env vars, and CI parity. When you change CLI-facing behavior, **prompt for out-of-sandbox permissions** and run them the same way, with **`required_permissions: ["all"]`** (and network) when using an agent shell.
292
+
246
293
### Sandbox and permissions
247
294
248
295
Commands that need network (e.g. `git push`, `gh pr create`, `npm install`) or full system access often fail in the sandbox with **TLS/certificate errors** (e.g. `x509: OSStatus -26276`) or auth prompts. These are sandbox restrictions, not broken tooling.
249
296
250
-
**Prefer requesting elevated permissions** (e.g. `required_permissions: ["all"]` or `["network"]`) and asking the user to approve so the agent can retry the command. Do not default to prompting the user to run commands themselves when elevation is available. Only fall back to copy-pasteable commands when elevated permissions are not an option.
297
+
**Prompt the user for permission to run outside the sandbox** (e.g. **`required_permissions: ["all"]`** or **`["network"]`**) and **re-run the same command** after they approve. See **Agent command execution** above. Only fall back to copy-pasteable “run this locally” instructions when elevation is refused or unavailable.
251
298
252
299
### Git commits (GPG)
253
300
254
301
**Always use GPG-signed commits** (`git commit -S`, or `commit.gpgsign=true`in git config). **Do not** use `--no-gpg-sign` to bypass signing.
255
302
256
-
In restricted environments, signing may fail with errors like “No agent running” or “Operation not permitted” on `~/.gnupg`. **Re-run the commit with full permissions** so `gpg-agent` is reachable, or sign from a normal local terminal. Unsigned commits should not be pushed as a shortcut.
303
+
In restricted environments, signing may fail with errors like “No agent running” or “Operation not permitted” on `~/.gnupg`. **Prompt for permission to run the commit outside the sandbox**(full permissions) so `gpg-agent` is reachable; only if that still fails, suggest the user sign from a normal local terminal. Unsigned commits should not be pushed as a shortcut.
257
304
258
305
### Linting and Formatting
259
306
```bash
@@ -277,12 +324,13 @@ go run cmd/hookdeck/main.go login --help
277
324
```
278
325
279
326
### Sandbox and command execution
280
-
- **Always run tests** when changing code: unit tests (`go test ./pkg/...`) and, for CLI-facing changes, acceptance tests (`go test ./test/acceptance/...`). Do not skip tests to avoid failures.
281
-
- When running commands (build, test, acceptance tests), if you see **TLS/certificate errors** (e.g. `x509: certificate verify failed`, `tls: failed to verify certificate`), **permission errors** (e.g. `operation not permitted` when writing to the Go module cache), or similar failures that look environment-related, the command is likely running inside a **sandbox**. **Prompt the user** and **re-run the command with elevated permissions** (e.g. `required_permissions: ["network"]`for tests that need API access, or `["all"]` to disable the sandbox) so the operation can succeed. Do not treat a build or test as passed if stderr shows these errors, even when the process exit code is 0.
327
+
- **Always run tests** when changing code: **`go test ./...`** from the repo root (see **Running `go test` after code changes** above), and for CLI-facing changes, acceptance tests with the appropriate **`-tags=...`** (see `test/acceptance/README.md`). Do not skip tests to avoid failures.
328
+
- For **`go test`**in this repo, **prompt for out-of-sandbox execution** and use **`required_permissions: ["all"]`** (and **`["network"]`** when needed) so the Go module cache works (see **Running `go test` after code changes**). Same for acceptance tests that call the real API.
329
+
- When you see **TLS/certificate errors**, **`no required module provides package`** during `go test`, **permission errors** on the module cache, or similar environment-related failures, **prompt for full/out-of-sandbox permissions** and **re-run** (with **`GOMODCACHE=...`**if needed)—**do not** treat the run as passed, and **do not** default to asking the user to run the command manually unless they declined elevation.
282
330
283
331
### GitHub CLI (`gh`)
284
332
- Use the **[GitHub CLI](https://cli.github.com/) (`gh`)** to read GitHub data and perform actions from the shell: **workflow runs and job logs** (e.g. `gh run list`, `gh run view <run-id> --log-failed`, `gh run view <run-id> --job <job-id> --log`), **PRs and checks** (`gh pr view`, `gh pr checks`, `gh pr diff`), **API access** (`gh api`), and creating or updating PRs, issues, and releases.
285
-
- Install and authenticate `gh` where needed (e.g. `gh auth login`). If `gh` fails with TLS, network, or permission errors, re-run with **network** or **all** permissions when the agent sandbox may be blocking access.
333
+
- Install and authenticate `gh` where needed (e.g. `gh auth login`). If `gh` fails with TLS, network, or permission errors, **prompt for permission** to re-run with **network** or **all** permissions when the agent sandbox may be blocking access.
286
334
287
335
## 6. Documentation Standards
288
336
@@ -358,7 +406,7 @@ if apiErr, ok := err.(*hookdeck.APIError); ok {
358
406
359
407
## 9. Testing Guidelines
360
408
361
-
- **Always run tests** when changing code. Run unit tests (`go test ./pkg/...`) and, for CLI-facing changes, acceptance tests (`go test ./test/acceptance/...`). If tests fail due to TLS/network/sandbox (e.g. `x509`, `operation not permitted`), prompt the user and re-run with elevated permissions (e.g. `required_permissions: ["all"]`) so tests can pass.
409
+
- **Always run tests** when changing code. Run **`go test ./...`** from the repo root (see **§5 Running `go test` after code changes**). For CLI-facing changes, run acceptance tests with the correct **`-tags=...`** per `test/acceptance/README.md`. **Agents:** **prompt for out-of-sandbox / full permissions**, then run `go test` with **`required_permissions: ["all"]`** (and network if needed) so the module cache works—**do not** push the user to run tests manually unless elevation is refused.
362
410
- **Create tests for new functionality.** Add unit tests for validation and business logic; add acceptance tests for flows that use the CLI as a user or agent would (success and failure paths). Acceptance tests must pass or fail—no skipping to avoid failures.
363
411
364
412
### Acceptance Test Setup
@@ -384,7 +432,8 @@ Acceptance tests in `test/acceptance/` are partitioned by **feature build tags**
384
432
|---------|---------|
385
433
| `go run cmd/hookdeck/main.go --help` | View CLI help |
Read **[AGENTS.md](AGENTS.md)** first for project structure, testing, and CLI conventions.
4
-
5
-
Repo-specific agent workflows (e.g. releases) live under **[skills/](skills/)** — see `skills/hookdeck-cli-release/` for cutting GitHub releases and drafting release notes.
3
+
Read **[AGENTS.md](AGENTS.md)** for all agent instructions (project structure, testing, sandbox permissions, CLI conventions, **`skills/`** workflows, and releases).
0 commit comments