ccproxy.services.cli_detection¶
ccproxy.services.cli_detection
¶
Centralized CLI detection service for all plugins.
This module provides a unified interface for detecting CLI binaries, checking versions, and managing CLI-related state across all plugins. It eliminates duplicate CLI detection logic by consolidating common patterns.
CLIDetectionResult
¶
CLIDetectionService
¶
Centralized service for CLI detection across all plugins.
This service provides: - Unified binary detection using BinaryResolver - Version detection with caching - Fallback data support for when CLI is not available - Consistent logging and error handling
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Settings
|
Application settings |
required |
binary_resolver
|
BinaryResolver | None
|
Optional binary resolver instance. If None, creates a new one. |
None
|
Source code in ccproxy/services/cli_detection.py
detect_cli
async
¶
detect_cli(
binary_name,
package_name=None,
version_flag="--version",
version_parser=None,
fallback_data=None,
cache_key=None,
)
Detect a CLI binary and its version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_name
|
str
|
Name of the binary to detect (e.g., "claude", "codex") |
required |
package_name
|
str | None
|
NPM package name if different from binary name |
None
|
version_flag
|
str
|
Flag to get version (default: "--version") |
'--version'
|
version_parser
|
Any | None
|
Optional callable to parse version output |
None
|
fallback_data
|
dict[str, Any] | None
|
Optional fallback data if CLI is not available |
None
|
cache_key
|
str | None
|
Optional cache key (defaults to binary_name) |
None
|
Returns:
| Type | Description |
|---|---|
CLIDetectionResult
|
CLIDetectionResult with detection information |
Source code in ccproxy/services/cli_detection.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
load_cached_version
¶
Load cached version for a binary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_name
|
str
|
Name of the binary |
required |
cache_file
|
str | None
|
Optional cache file name |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Cached version string or None |
Source code in ccproxy/services/cli_detection.py
save_cached_version
¶
Save version to cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_name
|
str
|
Name of the binary |
required |
version
|
str
|
Version string to cache |
required |
cache_file
|
str | None
|
Optional cache file name |
None
|
additional_data
|
dict[str, Any] | None
|
Additional data to cache |
None
|
Source code in ccproxy/services/cli_detection.py
get_cli_info
¶
Get CLI information in standard format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_name
|
str
|
Name of the binary |
required |
Returns:
| Type | Description |
|---|---|
CLIInfo
|
CLIInfo dictionary with structured information |
Source code in ccproxy/services/cli_detection.py
clear_cache
¶
get_all_detected
¶
Get all detected CLI binaries.
Returns:
| Type | Description |
|---|---|
dict[str, CLIDetectionResult]
|
Dictionary of binary name to detection result |
Source code in ccproxy/services/cli_detection.py
detect_multiple
async
¶
Detect multiple CLI binaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binaries
|
list[tuple[str, str | None]]
|
List of (binary_name, package_name) tuples |
required |
parallel
|
bool
|
Whether to detect in parallel |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, CLIDetectionResult]
|
Dictionary of binary name to detection result |