feat(auth): add tw auth token view via cli-core attachTokenViewCommand#227
Merged
Conversation
Wire @doist/cli-core/auth's `attachTokenViewCommand` as a subcommand of the existing `tw auth token [token]` setter — `tw auth token view` prints the stored token to stdout (no envelope) so it is pipe-safe for shell composition (`eval $(tw auth token view)`, etc.). - Commander matches subcommand names before the parent action, so `tw auth token view` always dispatches to the view path; Twist OAuth tokens are opaque random strings, so a literal "view" cannot collide with a real token value. - Refuses to print when TWIST_API_TOKEN is set (cli-core's `TOKEN_FROM_ENV` guard) — the env var takes precedence elsewhere so printing the saved token would disclose a secret the CLI did not manage. - `--user <ref>` flag is exposed by cli-core unconditionally; matches the lone stored account via the existing `TwistTokenStore.active(ref)` path (id-or-label match through parseRef), so single-user semantics are preserved. No changes to the lib/ layer. Five new tests cover the happy path, TOKEN_FROM_ENV refusal, NOT_AUTHENTICATED, and --user id match/miss. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
doistbot
reviewed
May 16, 2026
Member
doistbot
left a comment
There was a problem hiding this comment.
This PR successfully introduces the tw auth token view subcommand to enable pipe-safe token printing via @doist/cli-core. It is a solid addition that mirrors established patterns while properly respecting environment variable precedence. A few adjustments are needed, specifically syncing the new command in the AI skill reference, using Vitest's vi.stubEnv() to prevent environment state leakage in tests, and tightening the stdout assertions to fully guarantee pipe-safe output.
- src/lib/skills/content.ts + regenerated skills/twist-cli/SKILL.md: update the agent-facing reference from the (always-wrong) `tw auth token --user <ref>` to the actual `tw auth token view [--user <ref>]` surface introduced by this PR. - src/commands/auth/auth.test.ts: switch the TOKEN_FROM_ENV setup to `vi.stubEnv` / `vi.unstubAllEnvs` so a developer's exported TWIST_API_TOKEN is restored after the suite runs (no cross-test leakage). Tighten stdout assertions: replace `toHaveBeenCalledWith` on `process.stdout.write` with full-payload comparison via a `stdoutPayload()` helper, and assert `consoleSpy` was not called, so any future preamble/trailer added to the view output would fail the pipe-safety contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
doist-release-bot Bot
added a commit
that referenced
this pull request
May 16, 2026
## [2.38.0](v2.37.0...v2.38.0) (2026-05-16) ### Features * **auth:** add `tw auth token view` via cli-core attachTokenViewCommand ([#227](#227)) ([9ae4388](9ae4388))
Contributor
|
🎉 This PR is included in version 2.38.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
@doist/cli-core/auth'sattachTokenViewCommandas a subcommand of the existingtw auth token [token]setter —tw auth token viewprints the stored token to stdout (no envelope) so it is pipe-safe for shell composition (eval $(tw auth token view), etc.).tw auth token viewalways dispatches to the view path — Twist OAuth tokens are opaque random strings, so a literal "view" cannot collide with a real token value.TWIST_API_TOKENis set (cli-core'sTOKEN_FROM_ENVguard): the env var takes precedence elsewhere, so printing the saved token would disclose a secret the CLI did not manage.--user <ref>flag is added by cli-core unconditionally; matches the lone stored account via the existingTwistTokenStore.active(ref)path (id-or-label match throughparseRef), so single-user semantics are preserved.No changes to the
lib/layer.Test plan
npm run type-checknpm run lint:checknpm test— 5 new tests (happy path,TOKEN_FROM_ENVrefusal,NOT_AUTHENTICATED,--userid match,--userid miss); 611 total passnpm run buildtw auth token --helpshows the newviewsubcommandtw auth token view --helpshows the--user <ref>flagtw auth login→tw auth token viewprints the bearer token →eval $(tw auth token view)pipes safelyTWIST_API_TOKEN=anything tw auth token viewexits withTOKEN_FROM_ENV🤖 Generated with Claude Code