Skip to content

feat: CLI and Configuration (F04)#44

Merged
leocamello merged 12 commits intomainfrom
003-cli-configuration
Feb 3, 2026
Merged

feat: CLI and Configuration (F04)#44
leocamello merged 12 commits intomainfrom
003-cli-configuration

Conversation

@leocamello
Copy link
Owner

Feature: CLI and Configuration (F04)

Implements comprehensive CLI interface and layered configuration system for Nexus.

Summary

  • ✅ All 17 functional requirements implemented (10 P0 + 7 P1)
  • ✅ All 18 acceptance criteria verified
  • ✅ 173 tests passing (151 unit + 10 CLI integration + 6 health + 6 doc)
  • ✅ Zero-config mode working
  • ✅ Full constitution compliance
  • ✅ All clippy warnings resolved

Commands Implemented

Command Description
nexus serve Start server with config layering
nexus backends list List backends with status filtering
nexus backends add Add backend with auto-type detection
nexus backends remove Remove backend by ID
nexus models List available models
nexus health Show system health status
nexus config init Generate config template
nexus completions Shell completion scripts

Configuration Precedence

CLI args > Environment vars > Config file > Defaults

Files Added/Modified

  • src/cli/ - 8 files (mod.rs, serve.rs, backends.rs, models.rs, health.rs, output.rs, config.rs, completions.rs)
  • src/config/ - 7 files (mod.rs, server.rs, routing.rs, logging.rs, backend.rs, discovery.rs, error.rs)
  • src/main.rs - Command routing
  • tests/cli_integration.rs - End-to-end CLI tests
  • specs/003-cli-configuration/ - spec.md, plan.md, tasks.md, walkthrough.md

Related Issues

Closes #27, #28, #29, #30, #31, #32, #33, #34, #35, #36, #37, #38, #39, #40, #41, #42, #43

Breaking Changes

None - new feature.

- Add Table of Contents and Big Picture section with analogy
- Use 'Breaking it down' tables for configuration explanations
- Add step-by-step explanations with 'What this tests' callouts
- Include state machine diagram for status transitions
- Add Key Rust Concepts reference table
- Add Common Patterns section with code examples
- Match style of Backend Registry walkthrough

Audience: Junior developers joining the project
- Define all CLI commands (serve, backends, models, health, config)
- Document complete TOML configuration format
- Specify config precedence: CLI > env > file > defaults
- Define environment variable overrides (NEXUS_*)
- Include data structures for NexusConfig and clap Args
- Add 15 functional requirements and 5 NFRs
- Define error handling with helpful messages
- Include 18 acceptance criteria
- Tech stack: clap (derive), config, toml, comfy-table

Priority: P0 (Core MVP)
Depends on: F02 Backend Registry, F03 Health Checker
7 phases covering:
- Phase 1: Configuration module with layered loading (10 tests)
- Phase 2: CLI command definitions with clap derive (8 tests)
- Phase 3: Output formatting with comfy-table (6 tests)
- Phase 4: Serve command with graceful shutdown (8 tests)
- Phase 5: Query commands (backends, models, health) (10 tests)
- Phase 6: Config init command (4 tests)
- Phase 7: Integration tests with assert_cmd (10 tests)

Total: 56 tests (46 unit + 10 integration)

New dependencies: comfy-table, config crate, colored
Tech: clap derive, TOML config, tracing subscriber
16 tasks totaling ~27 hours:
- T01-T05: Configuration module (10h)
- T06-T07: CLI definitions and output (4h)
- T08: Serve command (3h)
- T09-T13: Query commands and config init (8h)
- T14-T16: Shutdown, integration tests, docs (5.5h)

66 tests total:
- 52 unit tests
- 10 integration tests (assert_cmd)
- 4 doc tests

Each task is:
- Completable in 1-4 hours
- Independently testable
- Has clear acceptance criteria
Decisions made:
1. Shell completions: Top-level 'nexus completions <shell>' command
   - Follows patterns from rustup, gh, kubectl
   - Added new FR-016 and T14 for completions

2. Config validation: Warn on unknown keys, continue loading
   - Forward compatible, catches typos in logs
   - Added FR-017 for unknown key warnings

3. Backend auto-detection: Auto-detect with fallback to generic
   - Detection order: Ollama → LlamaCpp → OpenAI → Generic
   - 2s timeout per endpoint, fallback to Generic on failure
   - Updated T10 with auto-detection tests and implementation

Updated artifacts:
- spec.md: Added Design Decisions section, completions command, FR-016/FR-017
- tasks.md: Added T14 (Completions), updated T10 (auto-detection), renumbered T15-T17
- Total tests: 70 (was 66)
…-T14)

Implements core CLI and configuration functionality for Nexus.

## Configuration Module
- NexusConfig with all sub-configs (server, routing, logging, discovery, health_check)
- TOML file loading with serde defaults
- Environment variable overrides (NEXUS_*)
- Proper enums with snake_case serialization

## CLI Module
- Full command structure using clap derive
- Commands: serve, backends, models, health, config, completions
- Table formatting with comfy-table
- JSON output support
- Colored status indicators

## Working Commands
- `nexus config init` - Initialize configuration file
- `nexus completions <shell>` - Generate shell completions
- `nexus --help` - Show help information

## Testing
- 127 tests passing (19 config + 18 cli + 84 registry + 6 health)
- Zero clippy warnings
- Release binary: 924KB

## Files Added
- src/config/ (8 files) - Configuration module
- src/cli/ (8 files) - CLI module

## Next Steps
- T08-T12: Implement command handlers (serve, backends, models, health)
- T15: Graceful shutdown
- T16: Integration tests
- T17: Documentation
Complete implementation of CLI and Configuration feature:

- T08: Serve command with config loading, tracing init, health checker
- T09: Backends list command with status filtering and JSON output
- T10: Backends add/remove with auto-detection (Ollama→LlamaCpp→OpenAI→Generic)
- T11: Models command with aggregation across backends
- T12: Health command showing system status and uptime
- T15: Graceful shutdown on SIGINT/SIGTERM
- T16: 10 CLI integration tests using assert_cmd

Total: 171 tests passing
All clippy warnings resolved
- Add module-level documentation with examples to config and cli modules
- Add doc comments to NexusConfig struct with usage examples
- Update README with comprehensive CLI command reference
- Add environment variables documentation
- Apply cargo fmt formatting
- All 173 tests passing (151 unit + 10 CLI integration + 6 health + 6 doc)
- Remove unused chrono::Utc import in registry tests
- Prefix unused test variables with underscore
- Allow deprecated cargo_bin in CLI integration tests
- Use struct initializer syntax instead of field assignment
@leocamello leocamello merged commit de63cb8 into main Feb 3, 2026
8 checks passed
@leocamello leocamello deleted the 003-cli-configuration branch February 3, 2026 01:22
@leocamello leocamello added enhancement New feature or request cli-config CLI & Configuration feature (F04) P0 MVP Priority labels Feb 3, 2026
leocamello added a commit that referenced this pull request Feb 17, 2026
Squash merge F04: CLI and Configuration

Implements comprehensive CLI interface and layered configuration system.

Review notes:
- Signal handler panic on installation failure is acceptable (matches tokio patterns)
- api_key_env field is a placeholder for F05 (Authentication feature)
leocamello added a commit that referenced this pull request Feb 17, 2026
Squash merge F04: CLI and Configuration

Implements comprehensive CLI interface and layered configuration system.

Review notes:
- Signal handler panic on installation failure is acceptable (matches tokio patterns)
- api_key_env field is a placeholder for F05 (Authentication feature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-config CLI & Configuration feature (F04) enhancement New feature or request P0 MVP Priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI & Configuration] T01: Add Dependencies & Module Scaffolding

1 participant