Skip to content

Add X-Gusto-CLI-Command request header per command - #166

Open
azrosen92 wants to merge 2 commits into
mainfrom
aint-805-cli-command-header
Open

Add X-Gusto-CLI-Command request header per command#166
azrosen92 wants to merge 2 commits into
mainfrom
aint-805-cli-command-header

Conversation

@azrosen92

Copy link
Copy Markdown
Contributor

What

Adds an X-Gusto-CLI-Command: <slug> request header to every Gusto API request the CLI makes. The slug is derived from the command name (e.g. api-request, employee-list), threaded via GlobalFlags → buildApiClient → ApiClient. No handler or helper signatures change.

Why

Today every request carries an identical User-Agent, so requests can be identified as coming from the CLI but not attributed to which command produced them — a raw gusto api request (the escape hatch) is indistinguishable from a first-class command. This header makes CLI traffic breakable-down by command for observability; the raw escape hatch surfaces as command:api-request, which is a command-gap signal.

The server-side consumer that turns this header into a span tag / metric ships separately.

Notes

  • The MCP path (callMcpTool, used by gusto feedback) also goes through buildApiClient, so those requests carry the header with their command slug — intended, accurate attribution.
  • OAuth login legs have no command context and are unaffected.
  • stdout envelope is unchanged.

Testing

Unit tests cover: the header set with the expected slug and omitted when absent; commandSlug mappings; the header riding through a 404; and the MCP path carrying the slug. typecheck + lint pass.

Related: AINT-805. This is one of three CLI PRs for the ticket; it and the feedback-nudge PR both touch runner.ts, so whichever merges second needs a trivial rebase.

🤖 Generated with Claude Code

azrosen92 and others added 2 commits August 18, 2026 15:23
Stamp every Gusto API request with an X-Gusto-CLI-Command header carrying a
slug of the command that issued it (e.g. employee-list, api-request), so
request-log analytics can break CLI traffic down by command. Both structured
commands and the raw `api request` escape hatch now carry it.

Threaded via GlobalFlags -> buildApiClient -> ApiClient with no handler or
helper signature changes: the runner injects the dispatched command onto a
fresh globals copy, buildApiClient slugs it, and the client sets the header
alongside the existing Authorization/Accept/version/User-Agent headers. The
header rides every attempt, including a 404'd request. Surfaces with no command
context (OAuth login) send nothing.

Signed-off-by: Aaron Rosen <aaron.rosen@gusto.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The feedback command and any callMcpTool request build their client via the
same buildApiClient path as the REST surfaces, so they carry
X-Gusto-CLI-Command too. This is intended: the header attributes each API
request to the command that issued it, and feedback is a real command. Add a
focused unit test that stubs the transport, drives callMcpTool with a feedback
command context, and asserts the outbound request carries the `feedback` slug.

Also reflow a runner test line to satisfy the formatter.

Signed-off-by: Aaron Rosen <aaron.rosen@gusto.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@azrosen92
azrosen92 requested review from a team and ashieh as code owners August 18, 2026 21:52
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.

2 participants