codedd-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codedd_cli-0.1.0/LICENSE +21 -0
- codedd_cli-0.1.0/PKG-INFO +276 -0
- codedd_cli-0.1.0/README.md +241 -0
- codedd_cli-0.1.0/codedd_cli/__init__.py +3 -0
- codedd_cli-0.1.0/codedd_cli/__main__.py +19 -0
- codedd_cli-0.1.0/codedd_cli/api/__init__.py +4 -0
- codedd_cli-0.1.0/codedd_cli/api/client.py +118 -0
- codedd_cli-0.1.0/codedd_cli/api/endpoints.py +44 -0
- codedd_cli-0.1.0/codedd_cli/api/exceptions.py +25 -0
- codedd_cli-0.1.0/codedd_cli/auditor/__init__.py +6 -0
- codedd_cli-0.1.0/codedd_cli/auditor/architecture_analyzer.py +1241 -0
- codedd_cli-0.1.0/codedd_cli/auditor/architecture_prompts.py +171 -0
- codedd_cli-0.1.0/codedd_cli/auditor/complexity_analyzer.py +942 -0
- codedd_cli-0.1.0/codedd_cli/auditor/dependency_scanner.py +2478 -0
- codedd_cli-0.1.0/codedd_cli/auditor/file_auditor.py +572 -0
- codedd_cli-0.1.0/codedd_cli/auditor/git_stats_collector.py +332 -0
- codedd_cli-0.1.0/codedd_cli/auditor/response_parser.py +487 -0
- codedd_cli-0.1.0/codedd_cli/auditor/vulnerability_validator.py +324 -0
- codedd_cli-0.1.0/codedd_cli/auth/__init__.py +4 -0
- codedd_cli-0.1.0/codedd_cli/auth/session.py +41 -0
- codedd_cli-0.1.0/codedd_cli/auth/token_manager.py +87 -0
- codedd_cli-0.1.0/codedd_cli/cli.py +69 -0
- codedd_cli-0.1.0/codedd_cli/commands/__init__.py +1 -0
- codedd_cli-0.1.0/codedd_cli/commands/audit_cmd.py +1877 -0
- codedd_cli-0.1.0/codedd_cli/commands/audits_cmd.py +273 -0
- codedd_cli-0.1.0/codedd_cli/commands/auth_cmd.py +230 -0
- codedd_cli-0.1.0/codedd_cli/commands/config_cmd.py +454 -0
- codedd_cli-0.1.0/codedd_cli/commands/scope_cmd.py +967 -0
- codedd_cli-0.1.0/codedd_cli/config/__init__.py +4 -0
- codedd_cli-0.1.0/codedd_cli/config/constants.py +22 -0
- codedd_cli-0.1.0/codedd_cli/config/settings.py +369 -0
- codedd_cli-0.1.0/codedd_cli/llm/__init__.py +1 -0
- codedd_cli-0.1.0/codedd_cli/llm/key_manager.py +271 -0
- codedd_cli-0.1.0/codedd_cli/models/__init__.py +5 -0
- codedd_cli-0.1.0/codedd_cli/models/account.py +13 -0
- codedd_cli-0.1.0/codedd_cli/models/audit.py +32 -0
- codedd_cli-0.1.0/codedd_cli/models/local_directory.py +26 -0
- codedd_cli-0.1.0/codedd_cli/scanner/__init__.py +18 -0
- codedd_cli-0.1.0/codedd_cli/scanner/file_classifier.py +247 -0
- codedd_cli-0.1.0/codedd_cli/scanner/file_walker.py +207 -0
- codedd_cli-0.1.0/codedd_cli/scanner/line_counter.py +75 -0
- codedd_cli-0.1.0/codedd_cli/utils/__init__.py +1 -0
- codedd_cli-0.1.0/codedd_cli/utils/directory_validator.py +179 -0
- codedd_cli-0.1.0/codedd_cli/utils/display.py +493 -0
- codedd_cli-0.1.0/codedd_cli/utils/payload_inspector.py +180 -0
- codedd_cli-0.1.0/codedd_cli/utils/security.py +14 -0
- codedd_cli-0.1.0/codedd_cli/utils/validators.py +37 -0
- codedd_cli-0.1.0/pyproject.toml +58 -0
codedd_cli-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CodeDD Limited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codedd-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI tool for CodeDD — run code audits from your terminal
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: code-audit,security,cli,codedd
|
|
8
|
+
Author: CodeDD
|
|
9
|
+
Author-email: support@codedd.ai
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Requires-Dist: httpx (>=0.27.0)
|
|
24
|
+
Requires-Dist: keyring (>=25.0.0)
|
|
25
|
+
Requires-Dist: lizard (>=1.17.0)
|
|
26
|
+
Requires-Dist: radon (>=6.0.0)
|
|
27
|
+
Requires-Dist: rich (>=13.0.0)
|
|
28
|
+
Requires-Dist: tomli (>=2.0.0) ; python_version < "3.11"
|
|
29
|
+
Requires-Dist: tomli-w (>=1.0.0)
|
|
30
|
+
Requires-Dist: typer[all] (>=0.9.0)
|
|
31
|
+
Project-URL: Homepage, https://codedd.ai
|
|
32
|
+
Project-URL: Repository, https://github.com/codedd/codedd-cli
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# CodeDD CLI
|
|
36
|
+
|
|
37
|
+
**Run code audits from your terminal.** The CodeDD CLI lets you define scope locally, run file-level and complexity analysis on your machine (using your own LLM API keys), and sync results to [CodeDD](https://codedd.ai) for consolidation, recommendations, and dashboards.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## What is CodeDD CLI?
|
|
42
|
+
|
|
43
|
+
CodeDD CLI is the official command-line interface for the CodeDD platform. You:
|
|
44
|
+
|
|
45
|
+
- **Define scope** — Add one or more local Git repository roots to an audit.
|
|
46
|
+
- **Run analysis locally** — File audits (LLM-based) and complexity metrics run on your machine; only metadata and results are sent to CodeDD.
|
|
47
|
+
- **Sync to CodeDD** — Scope metadata, audit results, complexity data, dependencies, and architecture are submitted to CodeDD, where consolidation, dependency enrichment, security scoring, and recommendations run on the server.
|
|
48
|
+
|
|
49
|
+
Ideal for teams who want to keep source code local while still using CodeDD’s analytics, recommendations, and reporting.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
- **Scope management** — Add/remove local directories, sync with CodeDD, detect changes and re-confirm scope (delta updates).
|
|
56
|
+
- **Local file auditing** — LLM-based file analysis using your Anthropic or OpenAI API keys; supports batching and progress feedback.
|
|
57
|
+
- **Complexity analysis** — Cyclomatic complexity and Halstead metrics (Radon/Lizard) run locally and are submitted to CodeDD.
|
|
58
|
+
- **Dependency scanning** — Local lockfile/manifest and import parsing; dependency data is sent to CodeDD for vulnerability and license analysis.
|
|
59
|
+
- **Architecture analysis** — Local component/relationship extraction with optional LLM enhancement; Phase 3 synthesis and storage on CodeDD.
|
|
60
|
+
- **Payment and budget** — Pre-flight checks, LoC budget deduction, or Stripe checkout when additional payment is required.
|
|
61
|
+
- **Secure auth** — CLI tokens stored in the OS credential store (Windows Credential Locker, macOS Keychain, Linux Secret Service).
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
### Requirements
|
|
68
|
+
|
|
69
|
+
- **Python 3.10+**
|
|
70
|
+
- A [CodeDD](https://codedd.ai) account and a CLI token (Account → CLI Access → Generate Token)
|
|
71
|
+
|
|
72
|
+
### From source (development)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/codedd/codedd-cli.git
|
|
76
|
+
cd codedd-cli
|
|
77
|
+
pip install -e .
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### From PyPI (when available)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install codedd-cli
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Verify:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
codedd --version
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Quick start
|
|
95
|
+
|
|
96
|
+
### 1. Authenticate
|
|
97
|
+
|
|
98
|
+
Generate a CLI token at [codedd.ai](https://codedd.ai) (Account → CLI Access), then:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
codedd auth login --token <your_token>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Or run `codedd auth login` and paste the token when prompted.
|
|
105
|
+
|
|
106
|
+
### 2. Select an audit
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
codedd audits list
|
|
110
|
+
codedd audits select
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Choose a **group audit** (multiple repos) or a **single audit** (one repo). The selected audit becomes the active context for scope and audit commands.
|
|
114
|
+
|
|
115
|
+
### 3. Define scope
|
|
116
|
+
|
|
117
|
+
Add the local paths that correspond to the audit’s repositories (each must be a Git repo root):
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
codedd scope add /path/to/my-repo
|
|
121
|
+
codedd scope list
|
|
122
|
+
codedd scope confirm
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`scope confirm` scans the directories, shows a preview (files, LoC), and registers scope with CodeDD. If you change files later, run `codedd audit start` — it will offer to re-sync scope (delta update) before starting.
|
|
126
|
+
|
|
127
|
+
### 4. Run an audit
|
|
128
|
+
|
|
129
|
+
Configure at least one LLM API key (used for file-level auditing):
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
codedd config set-key anthropic
|
|
133
|
+
# or: codedd config set-key openai
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Then start the audit:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
codedd audit start
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The CLI will:
|
|
143
|
+
|
|
144
|
+
- Sync scope with CodeDD (and prompt to re-confirm if local files changed).
|
|
145
|
+
- Run pre-flight checks (payment, LoC budget).
|
|
146
|
+
- Optionally open payment in the browser or deduct from budget.
|
|
147
|
+
- Fetch the audit plan, run file auditing and complexity analysis locally, submit results, submit dependencies, submit architecture, and trigger server-side post-processing (consolidation, recommendations, completion email).
|
|
148
|
+
|
|
149
|
+
Results and recommendations are available in the CodeDD dashboard; you can also run `codedd audits list` to see status.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Workflow overview
|
|
154
|
+
|
|
155
|
+
High-level flow:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
159
|
+
│ LOCAL │
|
|
160
|
+
│ 1. codedd audits select → Pick audit (group or single) │
|
|
161
|
+
│ 2. codedd scope add <path> → Add repo root(s) │
|
|
162
|
+
│ 3. codedd scope confirm → Scan & register scope with CodeDD │
|
|
163
|
+
│ 4. codedd audit start → Sync (if needed) → Pre-flight → Pay/budget │
|
|
164
|
+
│ └─ File audit (LLM) → Local │
|
|
165
|
+
│ └─ Complexity → Local │
|
|
166
|
+
│ └─ Submit results → CodeDD │
|
|
167
|
+
│ └─ Dependencies → Local scan → Submit → CodeDD │
|
|
168
|
+
│ └─ Architecture → Local phases → Submit → CodeDD │
|
|
169
|
+
│ └─ Complete → CodeDD runs consolidation & recommendations │
|
|
170
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
| Step | Where it runs | What happens |
|
|
174
|
+
|-------------------|---------------|--------------|
|
|
175
|
+
| Scope add/confirm | Local | Scan dirs, count files/LoC; register or delta-update scope on CodeDD. |
|
|
176
|
+
| Pre-flight | CodeDD | Check payment, budget, status. |
|
|
177
|
+
| File audit | Local | LLM (Anthropic/OpenAI) analyses each file; results sent to CodeDD. |
|
|
178
|
+
| Complexity | Local | Radon/Lizard; metrics sent to CodeDD. |
|
|
179
|
+
| Dependencies | Local + CodeDD| Lockfiles/imports sent; CodeDD does metadata, vulns, licenses. |
|
|
180
|
+
| Architecture | Local + CodeDD| Components/relations sent; CodeDD does Phase 3 and storage. |
|
|
181
|
+
| Recommendations | CodeDD | Consolidation, technical debt, security, licenses, etc. |
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Commands reference
|
|
186
|
+
|
|
187
|
+
### Authentication
|
|
188
|
+
|
|
189
|
+
| Command | Description |
|
|
190
|
+
|--------|-------------|
|
|
191
|
+
| `codedd auth login` | Log in with a CLI token (prompt or `--token`) |
|
|
192
|
+
| `codedd auth logout` | Clear stored credentials |
|
|
193
|
+
| `codedd auth status` | Show current account and token state |
|
|
194
|
+
|
|
195
|
+
### Audits
|
|
196
|
+
|
|
197
|
+
| Command | Description |
|
|
198
|
+
|--------|-------------|
|
|
199
|
+
| `codedd audits list` | List audits (`--type single\|group`, `--limit`, `--page`) |
|
|
200
|
+
| `codedd audits select [uuid]` | Set active audit (interactive if UUID omitted) |
|
|
201
|
+
|
|
202
|
+
### Scope
|
|
203
|
+
|
|
204
|
+
| Command | Description |
|
|
205
|
+
|--------|-------------|
|
|
206
|
+
| `codedd scope add <path> [path ...]` | Add Git repository root(s) to the active audit’s scope |
|
|
207
|
+
| `codedd scope remove <n>` | Remove directory by list number |
|
|
208
|
+
| `codedd scope list` | List directories in scope |
|
|
209
|
+
| `codedd scope clear` | Remove all directories from scope |
|
|
210
|
+
| `codedd scope status` | Show scope and sync state per directory |
|
|
211
|
+
| `codedd scope confirm` | Scan, preview, and register scope with CodeDD |
|
|
212
|
+
| `codedd scope sync` | Compare local vs CodeDD and show changes |
|
|
213
|
+
|
|
214
|
+
### Audit execution
|
|
215
|
+
|
|
216
|
+
| Command | Description |
|
|
217
|
+
|--------|-------------|
|
|
218
|
+
| `codedd audit start` | Sync scope (if needed), pre-flight, pay/budget, then run full local audit and submit to CodeDD. Use `--skip-sync` to skip scope sync; `--yes` to auto-confirm; `--debug-llm` for LLM debug output. |
|
|
219
|
+
|
|
220
|
+
### Configuration
|
|
221
|
+
|
|
222
|
+
| Command | Description |
|
|
223
|
+
|--------|-------------|
|
|
224
|
+
| `codedd config show` | Show current config (API URL, active audit, scope, etc.) |
|
|
225
|
+
| `codedd config set <key> <value>` | Set a config value |
|
|
226
|
+
| `codedd config set-key [anthropic\|openai]` | Store an LLM API key in the OS keychain |
|
|
227
|
+
| `codedd config show-keys` | List which providers have keys configured (not the keys themselves) |
|
|
228
|
+
| `codedd config provider [anthropic\|openai\|both]` | Set preferred LLM provider |
|
|
229
|
+
| `codedd config concurrency <n>` | Set max concurrent LLM requests (default 6) |
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Configuration
|
|
234
|
+
|
|
235
|
+
- **Config file:** `~/.codedd/config.toml` (TOML). Stores API URL, active audit, scope directories, LLM provider, concurrency. Permissions are restricted to the owner (Unix).
|
|
236
|
+
- **Secrets:** The CLI token and LLM API keys are stored in the system keychain (Windows Credential Locker, macOS Keychain, Linux Secret Service), not in the config file.
|
|
237
|
+
|
|
238
|
+
### Environment variables
|
|
239
|
+
|
|
240
|
+
| Variable | Purpose |
|
|
241
|
+
|---------|---------|
|
|
242
|
+
| `CODEDD_API_TOKEN` | Override the stored CLI token (e.g. for CI) |
|
|
243
|
+
| `CODEDD_API_URL` | Override API base URL (default from config) |
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Security
|
|
248
|
+
|
|
249
|
+
- CLI tokens and LLM keys are stored in the OS credential store, not in plaintext on disk.
|
|
250
|
+
- TLS certificate verification is always enabled for API requests.
|
|
251
|
+
- Config file and `~/.codedd` directory use owner-only permissions where supported.
|
|
252
|
+
- Tokens expire after 90 days (server-configurable); re-generate from the CodeDD dashboard when needed.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Development
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
pip install -e ".[dev]"
|
|
260
|
+
pytest
|
|
261
|
+
ruff check .
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
MIT License — see [LICENSE](LICENSE).
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Support
|
|
273
|
+
|
|
274
|
+
- **Issues:** [GitHub Issues](https://github.com/codedd/codedd-cli/issues)
|
|
275
|
+
- **Product:** [CodeDD](https://codedd.ai)
|
|
276
|
+
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# CodeDD CLI
|
|
2
|
+
|
|
3
|
+
**Run code audits from your terminal.** The CodeDD CLI lets you define scope locally, run file-level and complexity analysis on your machine (using your own LLM API keys), and sync results to [CodeDD](https://codedd.ai) for consolidation, recommendations, and dashboards.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## What is CodeDD CLI?
|
|
8
|
+
|
|
9
|
+
CodeDD CLI is the official command-line interface for the CodeDD platform. You:
|
|
10
|
+
|
|
11
|
+
- **Define scope** — Add one or more local Git repository roots to an audit.
|
|
12
|
+
- **Run analysis locally** — File audits (LLM-based) and complexity metrics run on your machine; only metadata and results are sent to CodeDD.
|
|
13
|
+
- **Sync to CodeDD** — Scope metadata, audit results, complexity data, dependencies, and architecture are submitted to CodeDD, where consolidation, dependency enrichment, security scoring, and recommendations run on the server.
|
|
14
|
+
|
|
15
|
+
Ideal for teams who want to keep source code local while still using CodeDD’s analytics, recommendations, and reporting.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **Scope management** — Add/remove local directories, sync with CodeDD, detect changes and re-confirm scope (delta updates).
|
|
22
|
+
- **Local file auditing** — LLM-based file analysis using your Anthropic or OpenAI API keys; supports batching and progress feedback.
|
|
23
|
+
- **Complexity analysis** — Cyclomatic complexity and Halstead metrics (Radon/Lizard) run locally and are submitted to CodeDD.
|
|
24
|
+
- **Dependency scanning** — Local lockfile/manifest and import parsing; dependency data is sent to CodeDD for vulnerability and license analysis.
|
|
25
|
+
- **Architecture analysis** — Local component/relationship extraction with optional LLM enhancement; Phase 3 synthesis and storage on CodeDD.
|
|
26
|
+
- **Payment and budget** — Pre-flight checks, LoC budget deduction, or Stripe checkout when additional payment is required.
|
|
27
|
+
- **Secure auth** — CLI tokens stored in the OS credential store (Windows Credential Locker, macOS Keychain, Linux Secret Service).
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
### Requirements
|
|
34
|
+
|
|
35
|
+
- **Python 3.10+**
|
|
36
|
+
- A [CodeDD](https://codedd.ai) account and a CLI token (Account → CLI Access → Generate Token)
|
|
37
|
+
|
|
38
|
+
### From source (development)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
git clone https://github.com/codedd/codedd-cli.git
|
|
42
|
+
cd codedd-cli
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### From PyPI (when available)
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install codedd-cli
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Verify:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
codedd --version
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
### 1. Authenticate
|
|
63
|
+
|
|
64
|
+
Generate a CLI token at [codedd.ai](https://codedd.ai) (Account → CLI Access), then:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
codedd auth login --token <your_token>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Or run `codedd auth login` and paste the token when prompted.
|
|
71
|
+
|
|
72
|
+
### 2. Select an audit
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
codedd audits list
|
|
76
|
+
codedd audits select
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Choose a **group audit** (multiple repos) or a **single audit** (one repo). The selected audit becomes the active context for scope and audit commands.
|
|
80
|
+
|
|
81
|
+
### 3. Define scope
|
|
82
|
+
|
|
83
|
+
Add the local paths that correspond to the audit’s repositories (each must be a Git repo root):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
codedd scope add /path/to/my-repo
|
|
87
|
+
codedd scope list
|
|
88
|
+
codedd scope confirm
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`scope confirm` scans the directories, shows a preview (files, LoC), and registers scope with CodeDD. If you change files later, run `codedd audit start` — it will offer to re-sync scope (delta update) before starting.
|
|
92
|
+
|
|
93
|
+
### 4. Run an audit
|
|
94
|
+
|
|
95
|
+
Configure at least one LLM API key (used for file-level auditing):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
codedd config set-key anthropic
|
|
99
|
+
# or: codedd config set-key openai
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Then start the audit:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
codedd audit start
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The CLI will:
|
|
109
|
+
|
|
110
|
+
- Sync scope with CodeDD (and prompt to re-confirm if local files changed).
|
|
111
|
+
- Run pre-flight checks (payment, LoC budget).
|
|
112
|
+
- Optionally open payment in the browser or deduct from budget.
|
|
113
|
+
- Fetch the audit plan, run file auditing and complexity analysis locally, submit results, submit dependencies, submit architecture, and trigger server-side post-processing (consolidation, recommendations, completion email).
|
|
114
|
+
|
|
115
|
+
Results and recommendations are available in the CodeDD dashboard; you can also run `codedd audits list` to see status.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Workflow overview
|
|
120
|
+
|
|
121
|
+
High-level flow:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
125
|
+
│ LOCAL │
|
|
126
|
+
│ 1. codedd audits select → Pick audit (group or single) │
|
|
127
|
+
│ 2. codedd scope add <path> → Add repo root(s) │
|
|
128
|
+
│ 3. codedd scope confirm → Scan & register scope with CodeDD │
|
|
129
|
+
│ 4. codedd audit start → Sync (if needed) → Pre-flight → Pay/budget │
|
|
130
|
+
│ └─ File audit (LLM) → Local │
|
|
131
|
+
│ └─ Complexity → Local │
|
|
132
|
+
│ └─ Submit results → CodeDD │
|
|
133
|
+
│ └─ Dependencies → Local scan → Submit → CodeDD │
|
|
134
|
+
│ └─ Architecture → Local phases → Submit → CodeDD │
|
|
135
|
+
│ └─ Complete → CodeDD runs consolidation & recommendations │
|
|
136
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| Step | Where it runs | What happens |
|
|
140
|
+
|-------------------|---------------|--------------|
|
|
141
|
+
| Scope add/confirm | Local | Scan dirs, count files/LoC; register or delta-update scope on CodeDD. |
|
|
142
|
+
| Pre-flight | CodeDD | Check payment, budget, status. |
|
|
143
|
+
| File audit | Local | LLM (Anthropic/OpenAI) analyses each file; results sent to CodeDD. |
|
|
144
|
+
| Complexity | Local | Radon/Lizard; metrics sent to CodeDD. |
|
|
145
|
+
| Dependencies | Local + CodeDD| Lockfiles/imports sent; CodeDD does metadata, vulns, licenses. |
|
|
146
|
+
| Architecture | Local + CodeDD| Components/relations sent; CodeDD does Phase 3 and storage. |
|
|
147
|
+
| Recommendations | CodeDD | Consolidation, technical debt, security, licenses, etc. |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Commands reference
|
|
152
|
+
|
|
153
|
+
### Authentication
|
|
154
|
+
|
|
155
|
+
| Command | Description |
|
|
156
|
+
|--------|-------------|
|
|
157
|
+
| `codedd auth login` | Log in with a CLI token (prompt or `--token`) |
|
|
158
|
+
| `codedd auth logout` | Clear stored credentials |
|
|
159
|
+
| `codedd auth status` | Show current account and token state |
|
|
160
|
+
|
|
161
|
+
### Audits
|
|
162
|
+
|
|
163
|
+
| Command | Description |
|
|
164
|
+
|--------|-------------|
|
|
165
|
+
| `codedd audits list` | List audits (`--type single\|group`, `--limit`, `--page`) |
|
|
166
|
+
| `codedd audits select [uuid]` | Set active audit (interactive if UUID omitted) |
|
|
167
|
+
|
|
168
|
+
### Scope
|
|
169
|
+
|
|
170
|
+
| Command | Description |
|
|
171
|
+
|--------|-------------|
|
|
172
|
+
| `codedd scope add <path> [path ...]` | Add Git repository root(s) to the active audit’s scope |
|
|
173
|
+
| `codedd scope remove <n>` | Remove directory by list number |
|
|
174
|
+
| `codedd scope list` | List directories in scope |
|
|
175
|
+
| `codedd scope clear` | Remove all directories from scope |
|
|
176
|
+
| `codedd scope status` | Show scope and sync state per directory |
|
|
177
|
+
| `codedd scope confirm` | Scan, preview, and register scope with CodeDD |
|
|
178
|
+
| `codedd scope sync` | Compare local vs CodeDD and show changes |
|
|
179
|
+
|
|
180
|
+
### Audit execution
|
|
181
|
+
|
|
182
|
+
| Command | Description |
|
|
183
|
+
|--------|-------------|
|
|
184
|
+
| `codedd audit start` | Sync scope (if needed), pre-flight, pay/budget, then run full local audit and submit to CodeDD. Use `--skip-sync` to skip scope sync; `--yes` to auto-confirm; `--debug-llm` for LLM debug output. |
|
|
185
|
+
|
|
186
|
+
### Configuration
|
|
187
|
+
|
|
188
|
+
| Command | Description |
|
|
189
|
+
|--------|-------------|
|
|
190
|
+
| `codedd config show` | Show current config (API URL, active audit, scope, etc.) |
|
|
191
|
+
| `codedd config set <key> <value>` | Set a config value |
|
|
192
|
+
| `codedd config set-key [anthropic\|openai]` | Store an LLM API key in the OS keychain |
|
|
193
|
+
| `codedd config show-keys` | List which providers have keys configured (not the keys themselves) |
|
|
194
|
+
| `codedd config provider [anthropic\|openai\|both]` | Set preferred LLM provider |
|
|
195
|
+
| `codedd config concurrency <n>` | Set max concurrent LLM requests (default 6) |
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Configuration
|
|
200
|
+
|
|
201
|
+
- **Config file:** `~/.codedd/config.toml` (TOML). Stores API URL, active audit, scope directories, LLM provider, concurrency. Permissions are restricted to the owner (Unix).
|
|
202
|
+
- **Secrets:** The CLI token and LLM API keys are stored in the system keychain (Windows Credential Locker, macOS Keychain, Linux Secret Service), not in the config file.
|
|
203
|
+
|
|
204
|
+
### Environment variables
|
|
205
|
+
|
|
206
|
+
| Variable | Purpose |
|
|
207
|
+
|---------|---------|
|
|
208
|
+
| `CODEDD_API_TOKEN` | Override the stored CLI token (e.g. for CI) |
|
|
209
|
+
| `CODEDD_API_URL` | Override API base URL (default from config) |
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Security
|
|
214
|
+
|
|
215
|
+
- CLI tokens and LLM keys are stored in the OS credential store, not in plaintext on disk.
|
|
216
|
+
- TLS certificate verification is always enabled for API requests.
|
|
217
|
+
- Config file and `~/.codedd` directory use owner-only permissions where supported.
|
|
218
|
+
- Tokens expire after 90 days (server-configurable); re-generate from the CodeDD dashboard when needed.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
pip install -e ".[dev]"
|
|
226
|
+
pytest
|
|
227
|
+
ruff check .
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
MIT License — see [LICENSE](LICENSE).
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Support
|
|
239
|
+
|
|
240
|
+
- **Issues:** [GitHub Issues](https://github.com/codedd/codedd-cli/issues)
|
|
241
|
+
- **Product:** [CodeDD](https://codedd.ai)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Allow running via ``python -m codedd_cli``."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from codedd_cli.api.exceptions import CodeDDConnectionError
|
|
6
|
+
from codedd_cli.cli import app
|
|
7
|
+
from codedd_cli.utils.display import print_error
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main() -> None:
|
|
11
|
+
try:
|
|
12
|
+
app()
|
|
13
|
+
except CodeDDConnectionError as e:
|
|
14
|
+
print_error(str(e))
|
|
15
|
+
sys.exit(1)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
main()
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""
|
|
2
|
+
HTTP client for communicating with the CodeDD API.
|
|
3
|
+
|
|
4
|
+
Wraps ``httpx`` with:
|
|
5
|
+
- Automatic ``X-CLI-Token`` header injection
|
|
6
|
+
- Configurable base URL from ``~/.codedd/config.toml``
|
|
7
|
+
- Retry logic with exponential back-off
|
|
8
|
+
- TLS certificate verification (enforced)
|
|
9
|
+
- Descriptive User-Agent header
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import time
|
|
13
|
+
from typing import Any, Optional
|
|
14
|
+
|
|
15
|
+
import httpx
|
|
16
|
+
|
|
17
|
+
from codedd_cli import __version__
|
|
18
|
+
from codedd_cli.api.exceptions import CodeDDConnectionError
|
|
19
|
+
from codedd_cli.auth.token_manager import TokenManager
|
|
20
|
+
from codedd_cli.config.constants import (
|
|
21
|
+
MAX_RETRIES,
|
|
22
|
+
REQUEST_TIMEOUT_SECONDS,
|
|
23
|
+
USER_AGENT_PREFIX,
|
|
24
|
+
)
|
|
25
|
+
from codedd_cli.config.settings import ConfigManager
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class CodeDDClient:
|
|
29
|
+
"""
|
|
30
|
+
Thin HTTP client that authenticates via the ``X-CLI-Token`` header.
|
|
31
|
+
|
|
32
|
+
Usage::
|
|
33
|
+
|
|
34
|
+
client = CodeDDClient()
|
|
35
|
+
resp = client.get("/api/cli/audits/", params={"limit": 20})
|
|
36
|
+
data = resp.json()
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, config: Optional[ConfigManager] = None) -> None:
|
|
40
|
+
self._config = config or ConfigManager()
|
|
41
|
+
self._base_url = self._config.api_url.rstrip("/")
|
|
42
|
+
self._token = TokenManager.retrieve()
|
|
43
|
+
|
|
44
|
+
# For localhost HTTP, disable TLS verification (not applicable anyway)
|
|
45
|
+
# For HTTPS, always verify certificates
|
|
46
|
+
verify_tls = not self._base_url.startswith("http://localhost") and not self._base_url.startswith("http://127.0.0.1")
|
|
47
|
+
|
|
48
|
+
self._client = httpx.Client(
|
|
49
|
+
base_url=self._base_url,
|
|
50
|
+
headers=self._build_headers(),
|
|
51
|
+
timeout=REQUEST_TIMEOUT_SECONDS,
|
|
52
|
+
verify=verify_tls,
|
|
53
|
+
follow_redirects=True,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def _build_headers(self) -> dict[str, str]:
|
|
57
|
+
headers: dict[str, str] = {
|
|
58
|
+
"User-Agent": f"{USER_AGENT_PREFIX}/{__version__}",
|
|
59
|
+
"Accept": "application/json",
|
|
60
|
+
}
|
|
61
|
+
if self._token:
|
|
62
|
+
headers["X-CLI-Token"] = self._token
|
|
63
|
+
return headers
|
|
64
|
+
|
|
65
|
+
# ---- HTTP verbs with retry ----
|
|
66
|
+
|
|
67
|
+
def get(self, path: str, **kwargs: Any) -> httpx.Response:
|
|
68
|
+
return self._request("GET", path, **kwargs)
|
|
69
|
+
|
|
70
|
+
def post(self, path: str, **kwargs: Any) -> httpx.Response:
|
|
71
|
+
return self._request("POST", path, **kwargs)
|
|
72
|
+
|
|
73
|
+
# ---- internal ----
|
|
74
|
+
|
|
75
|
+
def _request(self, method: str, path: str, **kwargs: Any) -> httpx.Response:
|
|
76
|
+
"""
|
|
77
|
+
Execute an HTTP request with automatic retries on transient errors.
|
|
78
|
+
|
|
79
|
+
Retries on 5xx responses and connection errors using exponential
|
|
80
|
+
back-off (1s, 2s, 4s …).
|
|
81
|
+
"""
|
|
82
|
+
last_exc: Optional[Exception] = None
|
|
83
|
+
|
|
84
|
+
for attempt in range(1, MAX_RETRIES + 1):
|
|
85
|
+
try:
|
|
86
|
+
resp = self._client.request(method, path, **kwargs)
|
|
87
|
+
|
|
88
|
+
# Don't retry client errors (4xx)
|
|
89
|
+
if resp.status_code < 500:
|
|
90
|
+
return resp
|
|
91
|
+
|
|
92
|
+
# Retry on server errors
|
|
93
|
+
if attempt < MAX_RETRIES:
|
|
94
|
+
time.sleep(2 ** (attempt - 1))
|
|
95
|
+
continue
|
|
96
|
+
|
|
97
|
+
return resp
|
|
98
|
+
|
|
99
|
+
except httpx.RequestError as exc:
|
|
100
|
+
last_exc = exc
|
|
101
|
+
if attempt < MAX_RETRIES:
|
|
102
|
+
time.sleep(2 ** (attempt - 1))
|
|
103
|
+
continue
|
|
104
|
+
raise CodeDDConnectionError() from None
|
|
105
|
+
|
|
106
|
+
# Should not normally reach here, but satisfy the type checker
|
|
107
|
+
if last_exc:
|
|
108
|
+
raise CodeDDConnectionError() from None
|
|
109
|
+
raise RuntimeError("Request failed after retries") # pragma: no cover
|
|
110
|
+
|
|
111
|
+
def close(self) -> None:
|
|
112
|
+
self._client.close()
|
|
113
|
+
|
|
114
|
+
def __enter__(self):
|
|
115
|
+
return self
|
|
116
|
+
|
|
117
|
+
def __exit__(self, *args):
|
|
118
|
+
self.close()
|