feat: Support the token, workspace, and endpoint in the environment - #602
Merged
Conversation
Credentials may now be given in the environment instead of being stored by "seam login" and "seam select workspace". Either variable, both, or neither may be set: whatever is set wins over what is stored. Resolve the token and workspace id in one place so every command sees the same credentials, report a clear error when either is missing, and warn when a command stores a credential the environment currently overrides. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014vMQhRm7UfP3WfSGBX6WUW
… command Move the environment variables into lib/env.ts and add SEAM_CLI_ENDPOINT, which overrides the server stored by "seam select server" the same way SEAM_CLI_TOKEN and SEAM_CLI_WORKSPACE_ID override the stored token and workspace. Commands that would store an overridden value now fail instead of storing something the environment ignores: "seam login" and "seam logout" while SEAM_CLI_TOKEN is set, "seam select workspace" while SEAM_CLI_WORKSPACE_ID is set, and "seam select server" while SEAM_CLI_ENDPOINT is set. Each reports what to unset, without a stack trace, and stores nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014vMQhRm7UfP3WfSGBX6WUW
Resolve the cli.ts imports and error reporting so UsageError from main and EnvVarOverrideError are both reported without a stack trace. Also declare the environment variables the CLI reads on NodeJS.ProcessEnv in src/lib/env.d.ts, and read them through that declared set. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014vMQhRm7UfP3WfSGBX6WUW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Everything
seam login,seam select workspace, andseam select serverstore may now be given in the environment instead:SEAM_CLI_TOKENseam loginSEAM_CLI_WORKSPACE_IDseam select workspaceSEAM_CLI_ENDPOINTseam select serverAny of them, all of them, or none of them may be set: each is resolved independently and wins over the corresponding stored value, so
SEAM_CLI_WORKSPACE_IDalone retargets the workspace while still using the stored token. Nothing needs to be logged in for a token given this way to work, which is what makes the CLI usable from CI.An API Key is scoped to a single workspace, so it needs no workspace id. A Personal Access Token works across workspaces, so it needs one from either
SEAM_CLI_WORKSPACE_IDorseam select workspace.Commands refuse rather than store an ignored value
Storing a value the environment overrides would leave a command that appears to succeed using something else, so those commands fail instead, name what to unset, and store nothing:
SEAM_CLI_TOKENblocksseam login(interactive and--token) andseam logoutSEAM_CLI_WORKSPACE_IDblocksseam select workspaceandseam login --workspace-idSEAM_CLI_ENDPOINTblocksseam select server,seam login --server, andseam config set fake-serverTwo placement details: the checks in the
loginbranch all run before any write and beforevalidateToken, so a rejected login neither hits the network nor stores half its arguments; and theselect workspacecheck runs before the non-interactive check, so scripts get the env var error instead of "cannot select in non-interactive mode". The workspace check also lives ininteractForWorkspaceId, covering the workspace prompt that interactiveseam logintriggers for a Personal Access Token.Errors are reported without a stack trace, like
UsageErrorandNonInteractiveError.Changes
src/lib/env.ts(new): the variable names, readers,EnvVarOverrideError, andassertEnvVarUnset. A value that is empty or only whitespace reads as unset; values are trimmed.src/lib/env.d.ts(new): declares the variables the CLI reads onNodeJS.ProcessEnv, and the readers only accept a name from that declared set.src/lib/get-credentials.ts(new):getToken()andgetWorkspaceId()resolve environment before stored config, so every command sees the same credentials.get-server.ts:SEAM_CLI_ENDPOINTwins over the stored server, which flows through every request,validateToken, and the stored-token lookup (tokens are keyed by server).get-seam.ts: resolves through the new modules and reports missing credentials asNot logged in: run "seam login" or set the SEAM_CLI_TOKEN environment variable/No workspace selected: ..., replacing the opaqueMissing personalAccessToken or workspaceIdfrom@seamapi/http.bin/cli.ts: the pre-command login gate accepts a token from the environment, and the commands above assert before storing.Tests
151 pass; lint, typecheck, and prettier are clean.
authorization), a token in the environment authenticates with nothing stored,seam-workspacecomes fromSEAM_CLI_WORKSPACE_ID,SEAM_CLI_ENDPOINTroutes requests to a server the stored config does not point at (with a control run proving the stored server is used without it), both missing-credential errors, and one refusal per command.runCliscrubsSEAM_CLI_*from the inherited environment so a developer's own shell cannot skew results.Docs
README gains an "Environment variables" section under Usage covering all three variables, the API Key vs Personal Access Token distinction, the refusal behavior, and CI examples.
🤖 Generated with Claude Code
https://claude.ai/code/session_014vMQhRm7UfP3WfSGBX6WUW