mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-15 22:21:20 +00:00
feat(targets): add multi-target CLI adapter system (Droid support)
Implement target adapter pattern enabling CCS CLI to support multiple backend targets (Claude, Droid) via pluggable adapters. Core additions: - TargetAdapter interface for pluggable target implementations - ClaudeAdapter and DroidAdapter concrete implementations - Target registry (singleton Map-based storage) - Target resolver with precedence: --target flag > per-profile config > busybox detection - Droid config manager with atomic writes and file locking to ~/.factory/settings.json - Droid binary detector to validate runtime environment - Adapter dispatch integrated into ccs.ts main execution flow - ccsd busybox alias for seamless Droid invocation - --target flag documentation in help - Session tracking enriched with target metadata - Dashboard target badge for visual identification Testing: - 43 unit tests covering resolver, registry, config manager, and adapters - Full coverage of target detection logic and edge cases Documentation: - Refactored system-architecture.md into modular docs/system-architecture/ subdirectory - Updated code-standards.md with target adapter guidelines - Updated codebase-summary.md with architecture overview - Updated maintainability baseline (33.8% → 35.2%) This establishes extensible foundation for multi-target support without breaking existing Claude workflows. Droid adapter is production-ready but defaults to Claude for backward compatibility.
This commit is contained in:
@@ -56,6 +56,16 @@ src/
|
||||
│ ├── update-command.ts # Self-update logic
|
||||
│ └── version-command.ts # Version display
|
||||
│
|
||||
├── targets/ # Multi-target adapter system (NEW)
|
||||
│ ├── index.ts # Barrel export
|
||||
│ ├── target-adapter.ts # TargetAdapter interface contract
|
||||
│ ├── target-registry.ts # Registry for runtime adapter lookup
|
||||
│ ├── target-resolver.ts # Resolution logic (flag > config > argv[0])
|
||||
│ ├── claude-adapter.ts # Claude Code CLI implementation
|
||||
│ ├── droid-adapter.ts # Factory Droid CLI implementation
|
||||
│ ├── droid-detector.ts # Droid binary detection & version checks
|
||||
│ └── droid-config-manager.ts # ~/.factory/settings.json management
|
||||
│
|
||||
├── auth/ # Authentication module
|
||||
│ ├── index.ts # Barrel export
|
||||
│ ├── commands/ # Auth-specific CLI commands
|
||||
@@ -181,6 +191,7 @@ src/
|
||||
| Category | Directories | Purpose |
|
||||
|----------|-------------|---------|
|
||||
| Core | `commands/`, `errors/` | CLI commands, error handling |
|
||||
| Targets | `targets/` | Multi-CLI adapter pattern (Claude Code, Factory Droid, extensible) |
|
||||
| Auth | `auth/`, `cliproxy/auth/` | Authentication across providers |
|
||||
| Config | `config/`, `types/` | Configuration & type definitions |
|
||||
| Providers | `cliproxy/`, `copilot/`, `glmt/` | Provider integrations (7 CLIProxy providers: gemini, codex, agy, qwen, iflow, kiro, ghcp) |
|
||||
@@ -190,6 +201,47 @@ src/
|
||||
| Services | `web-server/`, `api/` | HTTP server, API services |
|
||||
| Utilities | `utils/`, `management/` | Helpers, diagnostics |
|
||||
|
||||
### Target Adapter Module
|
||||
|
||||
The targets module provides an extensible interface for dispatching profiles to different CLI implementations.
|
||||
|
||||
**Key components:**
|
||||
|
||||
1. **TargetAdapter Interface** - Contract that each CLI implementation must fulfill:
|
||||
- `detectBinary()` - Find CLI binary on system (platform-specific)
|
||||
- `prepareCredentials()` - Deliver credentials (env vars vs config file writes)
|
||||
- `buildArgs()` - Construct target-specific argument list
|
||||
- `buildEnv()` - Construct environment for target CLI
|
||||
- `exec()` - Spawn target process (cross-platform)
|
||||
- `supportsProfileType()` - Verify profile compatibility
|
||||
|
||||
2. **Target Resolution** - Priority order:
|
||||
- `--target <cli>` flag (CLI argument)
|
||||
- Per-profile `target` field (from config.yaml)
|
||||
- `argv[0]` detection (busybox pattern: `ccsd` → droid)
|
||||
- Default: `claude`
|
||||
|
||||
3. **Implementations:**
|
||||
- **ClaudeAdapter** - Wraps existing behavior; delivers credentials via environment variables
|
||||
- **DroidAdapter** - New; writes to ~/.factory/settings.json and spawns with `-m custom:ccs-<profile>` flag
|
||||
|
||||
4. **Registry** - Map-based lookup (O(1)) for registered adapters at runtime
|
||||
|
||||
**Usage flow:**
|
||||
```
|
||||
Profile resolution (existing)
|
||||
↓
|
||||
Target resolution (via resolver.ts)
|
||||
↓
|
||||
Get adapter from registry
|
||||
↓
|
||||
Prepare credentials (adapter.prepareCredentials)
|
||||
↓
|
||||
Build args & env (adapter.buildArgs, buildEnv)
|
||||
↓
|
||||
Spawn target CLI (adapter.exec)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## UI Source (`ui/src/`)
|
||||
|
||||
Reference in New Issue
Block a user