Added comprehensive environment detection in runOnboardingFlow to skip
interactive prompts in test/CI environments. Detects:
- NODE_ENV=test
- CI=true
- VITEST=true
- GITHUB_ACTIONS=true
- \!process.stdin.isTTY
This prevents "The current environment doesn't support interactive
reading from TTY" errors in GitHub Actions CI.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Fix import order issues across multiple files
- Remove unused imports (loadAuthConfig, ValidationOptions)
- Add proper import group separations
- All lint checks and tests now pass
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Merge conflicts were handled by Claude AI - please verify the changes:
- src/commands/chat.ts: Integrated flag processing with main branch changes
- src/commands/serve.ts: Updated logger import and integrated flag processing
- src/services/index.ts: Updated logger import and maintained initialization logic
- src/services/index.test.ts: Accepted main branch version
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fix service initialization race condition where getAllTools() would return
all tools when ToolPermissionService wasn't ready, causing plan mode to
incorrectly include excluded tools like Bash.
The issue occurred in GitHub Actions where `cn -p` (plan mode) should exclude
Bash tool, but due to timing issues, Bash was being presented to the LLM and
then failing during execution with permission errors.
Changes:
- Fix getAllTools() to properly pass permissions to filterExcludedTools()
- Throw descriptive error when service not initialized instead of fallback
- Add comprehensive regression tests covering all modes and edge cases
Fixes automated PR review failures in GitHub Actions workflows.
The services/index.test.ts was failing in CI because it triggers the onboarding
flow which uses readlineSync, but CI environments don't have TTY access.
These tests are specifically for testing mode conversion logic (plan/auto/normal
to readonly/auto flags), not onboarding functionality. Onboarding is properly
tested in the dedicated onboarding.test.ts file.
- Add headless: true flag to all initializeServices() calls in tests
- This skips the onboarding flow and focuses on the actual logic being tested
- Maintains proper test coverage while fixing CI compatibility
Add concise documentation covering essential CLI usage patterns for end users.
Focuses on practical examples and common use cases rather than technical details.
Covers:
- Basic usage patterns (interactive vs headless)
- Configuration and permission modes
- Common examples for code analysis, scripting, and remote development
- Safety guidelines for --readonly vs --auto modes
Replaces scattered ad-hoc validation with a centralized, testable validation
system. Provides consistent error messages and comprehensive coverage of
flag combinations and edge cases.
Changes:
- Add flagValidator module with comprehensive validation functions
- Test coverage for all validation scenarios (17 tests)
- Replace scattered validation in index.ts with centralized validateFlags()
- Validate flag dependencies (--format/--silent require -p)
- Validate conflicting flags (--readonly vs --auto)
- Validate permission flag values (no empty tool names)
- Consistent error formatting and exit handling
All existing validation behavior preserved while adding new validations
for edge cases like empty permission tool names.
Eliminates major code duplication between TUI and headless modes by handling
onboarding internally within initializeServices(). Previously TUI mode called
initializeWithOnboarding() then startTUIChat() called initializeServices()
again, while headless mode called initializeServices() directly.
Changes:
- Add skipOnboarding option to ServiceInitOptions
- Modify initializeServices() to handle onboarding internally for TUI mode
- Remove duplicate initializeWithOnboarding() call from chat.ts TUI path
- Update startTUIChat() to skip initialization when already done
- Update serve.ts to use shared flag processing from Phase 1
This eliminates the dual initialization paths while preserving all existing
behavior. TUI mode now has single initialization path with proper onboarding.
Extract common flag processing logic from TUI and headless code paths into
shared flagProcessor module. This eliminates code duplication where both
paths independently converted readonly/auto flags to mode and structured
permission overrides.
Changes:
- Add src/flags/flagProcessor.ts with shared flag processing functions
- Replace duplicated logic in chat.ts (lines 168-173 and 259-264)
- Add comprehensive unit tests for all flag processing scenarios
- Add validation for conflicting --readonly and --auto flags
This is a pure refactor with no behavior changes. All existing functionality
preserved while eliminating 20+ lines of duplicated code.