Published as guidemode on npm. Commander.js-based CLI for interacting with the GuideMode server.
- Commander.js: Command-line interface framework
- TypeScript: Full type safety
- Chalk: Terminal text styling
- Open: Cross-platform URL opening
- Dual Build: Both ESM and CommonJS support
src/
├── cli.ts # Main CLI entry point and commands
├── auth.ts # Authentication flow implementation
└── index.ts # Package exports
# Build both ESM and CJS distributions
pnpm build
# Build ESM only
pnpm build:esm
# Build CJS only
pnpm build:cjs
# Development (watch mode)
pnpm dev
# Clean build artifacts
pnpm clean# Run tests with Vitest
pnpm test# From workspace root
pnpm cli
# Direct execution after build
node packages/cli/dist/esm/cli.jsIMPORTANT: Always run quality checks locally before committing changes.
Run these commands in the CLI package directory (packages/cli/) before committing:
# 1. Linting (REQUIRED - zero errors)
pnpm lint
# 2. Building (REQUIRED - must succeed)
# Builds both ESM and CJS distributions
pnpm build
# Note: No typecheck script exists yet (TypeScript checks run during build)
# Note: No tests exist yet - add tests when adding new featuresRun all checks in sequence:
# From packages/cli/
pnpm lint && pnpm buildIf any check fails, your code MUST NOT be committed. Fix all errors before proceeding.
- Zero tolerance: No lint errors or build failures allowed in commits
- Type safety: Proper TypeScript types throughout (no
anywithout justification) - Dual builds: Both ESM and CJS must build successfully
- Consistent style: Biome enforces consistent code formatting
Note: Currently no tests exist for the CLI package.
When adding tests in the future:
- Test new features: Add tests for all new functionality
- Keep it pragmatic: Focus on core CLI commands and auth flow
- Use existing patterns: Follow test patterns from other packages
- Run locally first: Always run tests before pushing
To check the CLI package from the workspace root:
pnpm --filter guidemode lint
pnpm --filter guidemode buildLogin:
guidemode login [--server <url>]- Default Server:
https://app.guidemode.dev - Flow: Opens browser for OAuth authentication
- Storage: Saves authentication token locally
Logout:
guidemode logout- Removes stored authentication token
- Confirms successful logout
Who Am I:
guidemode whoami- Shows current authenticated user
- Displays authentication status
ESM Build (tsconfig.json):
- Target: ES2022
- Module: ESNext
- Output:
dist/esm/ - Declaration: Type definitions included
CJS Build (tsconfig.cjs.json):
- Target: ES2022
- Module: CommonJS
- Output:
dist/cjs/ - Package Marker: Auto-generated
package.jsonwith"type": "commonjs"
Exports:
{
".": {
"types": "./dist/esm/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
}Binary:
{
"bin": {
"guidemode": "./dist/esm/cli.js"
}
}- Initiate: CLI opens browser to server OAuth endpoint
- Authorize: User grants permission via GitHub OAuth
- Callback: Server processes OAuth and returns token
- Storage: CLI saves token for future requests
- Verification: Subsequent commands use stored token
- Storage: Local file system (platform-specific)
- Security: Token stored securely with appropriate permissions
- Expiry: Automatic token refresh handling
- Validation: Server-side token verification
@guidemode/types: Shared TypeScript definitionschalk: Terminal colors and stylingcommander: CLI framework and argument parsingopen: Cross-platform browser opening
@types/node: Node.js type definitionstypescript: TypeScript compilervitest: Testing framework
# Login to default server
guidemode login
# Login to custom server
guidemode login --server https://api.guidemode.com
# Check authentication status
guidemode whoami
# Logout
guidemode logout# Install dependencies
pnpm install
# Build CLI
pnpm build
# Test CLI
pnpm test
# Run in development
pnpm dev- Dual Distribution: Supports both ESM and CJS for maximum compatibility
- Browser-based Auth: Uses system browser for OAuth flow
- Local Token Storage: Secure local storage for authentication
- Type Safety: Full TypeScript integration with shared types
- Cross-platform: Works on Windows, macOS, and Linux
- Minimal Dependencies: Focused dependency tree for fast installation
- Network Errors: Graceful handling of connection issues
- Authentication Errors: Clear messaging for auth failures
- Validation Errors: Input validation with helpful error messages
- Server Errors: Proper error propagation from API responses
The CLI is designed to easily add new commands:
program
.command('new-feature')
.description('Description of new feature')
.option('--option <value>', 'Feature option')
.action(async (options) => {
// Implementation
})Commands can leverage:
- Shared authentication system
- Common error handling patterns
- Consistent styling with Chalk
- Type-safe API integration