Skip to content

Commit 5fd9317

Browse files
authored
feat: add core functionality for vulnerability analysis and fix planning (#50)
* feat: add core functionality for vulnerability analysis and fix planning - Implemented configuration loading with environment variable support. - Added constants for GitHub API and default settings. - Created fix planner to generate actionable plans for vulnerabilities. - Developed GitHub service for interacting with GitHub repositories. - Introduced progress tracking for CLI operations. - Defined types for dependencies, vulnerabilities, and analysis results. - Added utility functions for formatting analysis and fix plan outputs. - Created a test API for validating programmatic interactions. - Configured TypeScript settings for building and type declarations. * vercelignore
1 parent 8206572 commit 5fd9317

22 files changed

Lines changed: 2596 additions & 1 deletion

.vercelignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/backend
1+
/backend
2+
/packages

packages/cli/.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# IDE
8+
.vscode/
9+
.idea/
10+
*.swp
11+
*.swo
12+
13+
# OS
14+
.DS_Store
15+
Thumbs.db
16+
17+
# Logs
18+
*.log
19+
npm-debug.log*
20+
21+
# Test coverage
22+
coverage/
23+
.nyc_output/
24+
25+
# Environment
26+
.env
27+
.env.*

packages/cli/.npmignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Source files (we only publish dist/)
2+
src/
3+
tsconfig.json
4+
*.ts
5+
!*.d.ts
6+
7+
# Dev files
8+
.gitignore
9+
*.spec.ts
10+
*.test.ts
11+
__tests__/
12+
coverage/
13+
.nyc_output/
14+
15+
# Build/dev tools
16+
tsup.config.ts
17+
.eslintrc*
18+
.prettierrc*
19+
*.config.js
20+
*.config.mjs
21+
*.config.ts
22+
23+
# IDE
24+
.vscode/
25+
.idea/
26+
*.swp
27+
*.swo
28+
29+
# OS
30+
.DS_Store
31+
Thumbs.db
32+
33+
# Logs
34+
*.log
35+
npm-debug.log*
36+
37+
# Test
38+
test/
39+
tests/

packages/cli/README.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# GitDepSec CLI
2+
3+
A powerful CLI tool for analyzing dependency vulnerabilities in your projects. Supports npm, PyPI, Maven, RubyGems, Composer, and Pub.
4+
5+
## Installation
6+
7+
```bash
8+
# Using npm
9+
npm install -g gitdepsec
10+
11+
# Using bun
12+
bun add -g gitdepsec
13+
14+
# Or run without installing
15+
bunx gitdepsec analyse
16+
npx gitdepsec analyse
17+
```
18+
19+
## Usage
20+
21+
### Analyze Local Project
22+
23+
```bash
24+
# Analyze package.json in current directory
25+
gds analyse
26+
27+
# Analyze specific file
28+
gds analyse -f package.json
29+
gds analyse -f requirements.txt
30+
gds analyse -f pom.xml
31+
32+
# Analyze multiple files
33+
gds analyse -f package.json -f requirements.txt
34+
```
35+
36+
### Analyze GitHub Repository
37+
38+
```bash
39+
# Public repository
40+
gds analyse --repo owner/repo
41+
42+
# Specific branch
43+
gds analyse --repo owner/repo --branch develop
44+
45+
# With GitHub token (for private repos or higher rate limits)
46+
gds analyse --repo owner/repo --token ghp_xxxxx
47+
```
48+
49+
### Output Formats
50+
51+
```bash
52+
# Default: colored table output
53+
gds analyse
54+
55+
# JSON output (for piping/scripting)
56+
gds analyse --format json
57+
58+
# Markdown output
59+
gds analyse --format markdown
60+
61+
# Save to file
62+
gds analyse --output report.json --format json
63+
```
64+
65+
### Include Transitive Dependencies
66+
67+
```bash
68+
# Transitive scanning is enabled by default
69+
gds analyse
70+
71+
# Disable transitive (direct dependencies only)
72+
gds analyse --no-transitive
73+
```
74+
75+
### Generate Fix Plan
76+
77+
```bash
78+
# Generate fix recommendations
79+
gds fix
80+
81+
# Fix specific file
82+
gds fix -f package.json
83+
84+
# Direct dependencies only
85+
gds fix --no-transitive
86+
87+
# Output as JSON
88+
gds fix --format json
89+
```
90+
91+
## Configuration
92+
93+
Create a `.gitdepsecrc` or `.gitdepsec.json` in your project root:
94+
95+
```json
96+
{
97+
"github_token": "ghp_xxxxx",
98+
"include_transitive": true,
99+
"output_format": "table"
100+
}
101+
```
102+
103+
Or use environment variables:
104+
105+
```bash
106+
export GITHUB_TOKEN=ghp_xxxxx
107+
export GDS_INCLUDE_TRANSITIVE=true
108+
export GDS_OUTPUT_FORMAT=table
109+
```
110+
111+
## Commands
112+
113+
| Command | Description |
114+
|---------|-------------|
115+
| `gds analyse` | Analyze dependencies for vulnerabilities |
116+
| `gds fix` | Generate fix recommendations |
117+
| `gds init` | Create configuration file |
118+
| `gds --version` | Show version |
119+
| `gds --help` | Show help |
120+
121+
## CLI Options Reference
122+
123+
### `gds analyse`
124+
125+
| Option | Description |
126+
|--------|-------------|
127+
| `-f, --file <files...>` | Manifest file(s) to analyze |
128+
| `-r, --repo <repo>` | GitHub repository in `owner/repo` format |
129+
| `-b, --branch <branch>` | Branch to analyze |
130+
| `-t, --token <token>` | GitHub personal access token |
131+
| `--no-transitive` | Disable transitive dependency scanning |
132+
| `--format <format>` | Output format: `table`, `json`, `markdown` |
133+
| `-o, --output <file>` | Save output to file |
134+
| `-q, --quiet` | Minimal output |
135+
| `-v, --verbose` | Verbose output |
136+
137+
### `gds fix`
138+
139+
| Option | Description |
140+
|--------|-------------|
141+
| `-f, --file <files...>` | Manifest file(s) to generate fixes for |
142+
| `-r, --repo <repo>` | GitHub repository in `owner/repo` format |
143+
| `-b, --branch <branch>` | Branch to analyze |
144+
| `-t, --token <token>` | GitHub personal access token |
145+
| `--no-transitive` | Disable transitive dependency scanning |
146+
| `--format <format>` | Output format: `table`, `json`, `markdown` |
147+
| `-o, --output <file>` | Save output to file |
148+
149+
## Supported Ecosystems
150+
151+
- **npm** - `package.json`
152+
- **PyPI** - `requirements.txt`
153+
- **Maven** - `pom.xml`
154+
- **RubyGems** - `Gemfile`
155+
- **Composer** - `composer.json`
156+
- **Pub** - `pubspec.yaml`
157+
158+
## Exit Codes
159+
160+
For `gds analyse`:
161+
162+
| Code | Description |
163+
|------|-------------|
164+
| 0 | Success, no vulnerabilities found |
165+
| 1 | Vulnerabilities found |
166+
| 2 | Error during analysis |
167+
168+
For `gds fix`:
169+
- `0`: Fix plan generated
170+
- `2`: Error during fix plan generation
171+
172+
## AI Harness Usage (Terminal)
173+
174+
Use the CLI directly from your AI harness/tool and consume structured JSON output.
175+
176+
```bash
177+
# Analyze local manifests as JSON
178+
gds analyse --format json
179+
180+
# Analyze a specific repo and save JSON output
181+
gds analyse --repo owner/repo --format json --output report.json
182+
183+
# Generate fix plan as JSON
184+
gds fix --format json
185+
```
186+
187+
## License
188+
189+
MIT

0 commit comments

Comments
 (0)