project-brain-cli 1.0.0__py3-none-any.whl
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.
- project_brain/__init__.py +1 -0
- project_brain/cli.py +644 -0
- project_brain/cli_help.py +52 -0
- project_brain/cli_ui.py +69 -0
- project_brain/config/__init__.py +0 -0
- project_brain/core/__init__.py +0 -0
- project_brain/core/analyzer.py +134 -0
- project_brain/core/config_loader.py +193 -0
- project_brain/core/differ.py +160 -0
- project_brain/core/doctor.py +29 -0
- project_brain/core/doctor_checks/analysis.py +110 -0
- project_brain/core/doctor_checks/environment.py +92 -0
- project_brain/core/doctor_checks/exports.py +70 -0
- project_brain/core/doctor_checks/llm.py +107 -0
- project_brain/core/doctor_checks/models.py +10 -0
- project_brain/core/doctor_checks/repository.py +102 -0
- project_brain/core/explainer.py +334 -0
- project_brain/core/explainer_file.py +136 -0
- project_brain/core/exporter.py +340 -0
- project_brain/core/logger.py +31 -0
- project_brain/core/results.py +163 -0
- project_brain/core/summarizer.py +108 -0
- project_brain/llm/__init__.py +0 -0
- project_brain/llm/provider.py +211 -0
- project_brain/storage/__init__.py +0 -0
- project_brain/storage/storage.py +12 -0
- project_brain_cli-1.0.0.dist-info/METADATA +1185 -0
- project_brain_cli-1.0.0.dist-info/RECORD +32 -0
- project_brain_cli-1.0.0.dist-info/WHEEL +5 -0
- project_brain_cli-1.0.0.dist-info/entry_points.txt +3 -0
- project_brain_cli-1.0.0.dist-info/licenses/LICENSE +11 -0
- project_brain_cli-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1185 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: project-brain-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: CLI-first developer intelligence tool
|
|
5
|
+
Author: Srujan Amaragatti
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: typer
|
|
11
|
+
Requires-Dist: rich
|
|
12
|
+
Requires-Dist: PyYAML
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# ๐ง project-brain
|
|
20
|
+
|
|
21
|
+
> **Developer Intelligence CLI for understanding codebases and code evolution at a semantic level.**
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+

|
|
25
|
+

|
|
26
|
+

|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ๐ What is project-brain?
|
|
32
|
+
|
|
33
|
+
`project-brain` is a CLI-first developer intelligence tool built for analyzing codebases, tracking Git changes at function level, generating structured exports for AI systems, and explaining code changes using optional LLM integrations.
|
|
34
|
+
|
|
35
|
+
Unlike traditional Git tooling that operates on raw line diffs, project-brain uses AST-based parsing to understand code structure and produce developer-friendly insights.
|
|
36
|
+
|
|
37
|
+
The project is designed around a **local-first**, **privacy-friendly**, and **AI-optional** workflow.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
# ๐ฏ Why project-brain Exists
|
|
42
|
+
|
|
43
|
+
Modern development workflows suffer from several problems:
|
|
44
|
+
|
|
45
|
+
### Git diffs are noisy
|
|
46
|
+
|
|
47
|
+
Traditional diffs show line changes, not semantic meaning.
|
|
48
|
+
|
|
49
|
+
A small refactor can generate large diffs while hiding the actual behavioral impact.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### Codebases become difficult to understand
|
|
54
|
+
|
|
55
|
+
Large repositories contain:
|
|
56
|
+
|
|
57
|
+
* deeply nested modules
|
|
58
|
+
* duplicated logic
|
|
59
|
+
* unclear ownership
|
|
60
|
+
* hidden dependencies
|
|
61
|
+
|
|
62
|
+
Understanding them manually is slow.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### AI tools require structured context
|
|
67
|
+
|
|
68
|
+
Most AI systems perform poorly when fed raw repositories.
|
|
69
|
+
|
|
70
|
+
project-brain creates:
|
|
71
|
+
|
|
72
|
+
* structured exports
|
|
73
|
+
* focused change sets
|
|
74
|
+
* function-level intelligence
|
|
75
|
+
* AI-friendly context
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### Local-first tooling matters
|
|
80
|
+
|
|
81
|
+
Many developers do not want:
|
|
82
|
+
|
|
83
|
+
* automatic code uploads
|
|
84
|
+
* cloud dependency
|
|
85
|
+
* vendor lock-in
|
|
86
|
+
|
|
87
|
+
project-brain works fully offline when:
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
llm:
|
|
91
|
+
provider: none
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
# โจ Features
|
|
97
|
+
|
|
98
|
+
## Implemented
|
|
99
|
+
|
|
100
|
+
* ๐ Recursive repository scanning
|
|
101
|
+
* ๐ง AST-based Python analysis
|
|
102
|
+
* ๐งฉ Function extraction
|
|
103
|
+
* ๐๏ธ Class extraction
|
|
104
|
+
* ๐ Git diff parsing
|
|
105
|
+
* ๐ Function-level change tracking
|
|
106
|
+
* ๐ฆ AI-friendly code export system
|
|
107
|
+
* ๐ค Optional LLM explanations
|
|
108
|
+
* ๐พ Explanation caching
|
|
109
|
+
* ๐ HTML diff reports
|
|
110
|
+
* โ ๏ธ Config validation
|
|
111
|
+
* ๐ฉบ Environment diagnostics
|
|
112
|
+
* ๐ชต Persistent logging
|
|
113
|
+
* ๐ซ Binary file skipping
|
|
114
|
+
* ๐ก๏ธ Invalid Python safety handling
|
|
115
|
+
* โก Deep directory traversal
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
# ๐๏ธ Architecture Overview
|
|
120
|
+
|
|
121
|
+
project-brain is structured into independent modules.
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
CLI Layer
|
|
125
|
+
โ
|
|
126
|
+
โโโ Analyzer
|
|
127
|
+
โโโ Diff Engine
|
|
128
|
+
โโโ Explain Engine
|
|
129
|
+
โโโ Export Engine
|
|
130
|
+
โโโ Doctor / Diagnostics
|
|
131
|
+
โโโ Config Validation
|
|
132
|
+
โโโ Logging System
|
|
133
|
+
โโโ LLM Provider Layer
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## ๐ Analyzer
|
|
139
|
+
|
|
140
|
+
Responsible for:
|
|
141
|
+
|
|
142
|
+
* filesystem traversal
|
|
143
|
+
* AST parsing
|
|
144
|
+
* metadata extraction
|
|
145
|
+
* hashing files
|
|
146
|
+
* extracting functions/classes
|
|
147
|
+
|
|
148
|
+
Uses Python `ast` module for semantic analysis.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## ๐ Diff Engine
|
|
153
|
+
|
|
154
|
+
Responsible for:
|
|
155
|
+
|
|
156
|
+
* Git diff parsing
|
|
157
|
+
* tracking modified files
|
|
158
|
+
* function-level change detection
|
|
159
|
+
* comparing AST extracted function bodies
|
|
160
|
+
|
|
161
|
+
Supports:
|
|
162
|
+
|
|
163
|
+
* added files
|
|
164
|
+
* modified files
|
|
165
|
+
* deleted files
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## ๐ง Explain Engine
|
|
170
|
+
|
|
171
|
+
Responsible for:
|
|
172
|
+
|
|
173
|
+
* generating semantic explanations
|
|
174
|
+
* producing structured summaries
|
|
175
|
+
* LLM provider integration
|
|
176
|
+
* caching explanations
|
|
177
|
+
* fallback behavior when AI disabled
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## ๐ฆ Export Engine
|
|
182
|
+
|
|
183
|
+
Responsible for:
|
|
184
|
+
|
|
185
|
+
* exporting entire repositories
|
|
186
|
+
* exporting changed code only
|
|
187
|
+
* generating AI-friendly code bundles
|
|
188
|
+
* structured file aggregation
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## ๐ค LLM Provider Layer
|
|
193
|
+
|
|
194
|
+
Supports:
|
|
195
|
+
|
|
196
|
+
* OpenAI
|
|
197
|
+
* Ollama
|
|
198
|
+
* Gemini
|
|
199
|
+
* HuggingFace
|
|
200
|
+
|
|
201
|
+
Provider abstraction includes:
|
|
202
|
+
|
|
203
|
+
* timeout handling
|
|
204
|
+
* model listing
|
|
205
|
+
* response normalization
|
|
206
|
+
* error handling
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## ๐พ Cache System
|
|
211
|
+
|
|
212
|
+
Explanation results are cached inside:
|
|
213
|
+
|
|
214
|
+
```text
|
|
215
|
+
.brain/cache/
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
This avoids repeated LLM calls for unchanged function diffs.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
# โ๏ธ Installation
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Requirements
|
|
227
|
+
|
|
228
|
+
* Python >= 3.10
|
|
229
|
+
* Git installed
|
|
230
|
+
* Optional:
|
|
231
|
+
|
|
232
|
+
* Ollama
|
|
233
|
+
* OpenAI API access
|
|
234
|
+
* Gemini API access
|
|
235
|
+
* HuggingFace API access
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Clone Repository
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
git clone <repo-url>
|
|
243
|
+
cd project-brain
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Create Virtual Environment
|
|
249
|
+
|
|
250
|
+
### Windows
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
python -m venv env
|
|
254
|
+
env\Scripts\activate
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Linux/macOS
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
python3 -m venv env
|
|
261
|
+
source env/bin/activate
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Install
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
pip install -e .
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## CLI Aliases
|
|
275
|
+
|
|
276
|
+
Both commands work:
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
brain
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
project-brain
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
# โก Quick Start (30 Seconds)
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 1. Initialize project-brain
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
brain project init
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Creates:
|
|
299
|
+
|
|
300
|
+
```text
|
|
301
|
+
.brain/
|
|
302
|
+
brain.yaml
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## 2. Analyze Repository
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
brain project analyze .
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Performs:
|
|
314
|
+
|
|
315
|
+
* recursive scan
|
|
316
|
+
* AST parsing
|
|
317
|
+
* metadata generation
|
|
318
|
+
|
|
319
|
+
Stores results inside:
|
|
320
|
+
|
|
321
|
+
```text
|
|
322
|
+
.brain/data.json
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## 3. Inspect Git Changes
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
brain diff show
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Default behavior:
|
|
334
|
+
|
|
335
|
+
```text
|
|
336
|
+
HEAD~1 โ HEAD
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Shows:
|
|
340
|
+
|
|
341
|
+
* modified files
|
|
342
|
+
* added files
|
|
343
|
+
* deleted files
|
|
344
|
+
* function-level changes
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## 4. Export AI-Friendly Context
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
brain export full_code
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Creates:
|
|
355
|
+
|
|
356
|
+
```text
|
|
357
|
+
.brain/exports/full_code.txt
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
# ๐ง Command Reference
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
# ๐ Project Commands
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## `brain project init`
|
|
371
|
+
|
|
372
|
+
Initialize project-brain.
|
|
373
|
+
|
|
374
|
+
### Syntax
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
brain project init
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### What It Does
|
|
381
|
+
|
|
382
|
+
Creates:
|
|
383
|
+
|
|
384
|
+
* `.brain/`
|
|
385
|
+
* `.brain/cache/`
|
|
386
|
+
* `.brain/data.json`
|
|
387
|
+
* `.brain/index.json`
|
|
388
|
+
* `brain.yaml`
|
|
389
|
+
|
|
390
|
+
### Notes
|
|
391
|
+
|
|
392
|
+
* Existing files are preserved
|
|
393
|
+
* Safe to rerun
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## `brain project analyze`
|
|
398
|
+
|
|
399
|
+
Analyze repository structure.
|
|
400
|
+
|
|
401
|
+
### Syntax
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
brain project analyze [path]
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Arguments
|
|
408
|
+
|
|
409
|
+
| Argument | Default | Description |
|
|
410
|
+
| -------- | ------- | -------------- |
|
|
411
|
+
| path | `.` | Root directory |
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
### Internal Behavior
|
|
416
|
+
|
|
417
|
+
* recursively traverses directories
|
|
418
|
+
* skips ignored paths
|
|
419
|
+
* skips binary files
|
|
420
|
+
* optionally skips tests
|
|
421
|
+
* extracts:
|
|
422
|
+
|
|
423
|
+
* functions
|
|
424
|
+
* classes
|
|
425
|
+
* hashes
|
|
426
|
+
* metadata
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
### Output
|
|
431
|
+
|
|
432
|
+
```text
|
|
433
|
+
.brain/data.json
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
### Example
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
brain project analyze .
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
---
|
|
445
|
+
|
|
446
|
+
### Edge Cases
|
|
447
|
+
|
|
448
|
+
* invalid Python files are skipped safely
|
|
449
|
+
* unreadable files do not crash analysis
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## `brain project summary`
|
|
454
|
+
|
|
455
|
+
Generate repository summary.
|
|
456
|
+
|
|
457
|
+
### Syntax
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
brain project summary
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### What It Shows
|
|
464
|
+
|
|
465
|
+
* total files
|
|
466
|
+
* total functions
|
|
467
|
+
* total classes
|
|
468
|
+
* top files by function count
|
|
469
|
+
* detected architecture hints
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
### Output Modes
|
|
474
|
+
|
|
475
|
+
Configured using:
|
|
476
|
+
|
|
477
|
+
```yaml
|
|
478
|
+
output:
|
|
479
|
+
format: text
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
Supported:
|
|
483
|
+
|
|
484
|
+
* text
|
|
485
|
+
* json
|
|
486
|
+
* markdown
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## `brain project doctor`
|
|
491
|
+
|
|
492
|
+
Validate environment setup.
|
|
493
|
+
|
|
494
|
+
### Syntax
|
|
495
|
+
|
|
496
|
+
```bash
|
|
497
|
+
brain project doctor
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Checks
|
|
501
|
+
|
|
502
|
+
* project initialized
|
|
503
|
+
* repository analyzed
|
|
504
|
+
* git availability
|
|
505
|
+
* config validity
|
|
506
|
+
* provider setup
|
|
507
|
+
* API key presence
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
### Final Status
|
|
512
|
+
|
|
513
|
+
| Status | Meaning |
|
|
514
|
+
| --------- | -------------------------- |
|
|
515
|
+
| READY | All required checks passed |
|
|
516
|
+
| PARTIAL | Some checks missing |
|
|
517
|
+
| NOT READY | Critical setup missing |
|
|
518
|
+
|
|
519
|
+
---
|
|
520
|
+
|
|
521
|
+
# ๐ Diff Commands
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
## `brain diff show`
|
|
526
|
+
|
|
527
|
+
Show repository changes.
|
|
528
|
+
|
|
529
|
+
### Syntax
|
|
530
|
+
|
|
531
|
+
```bash
|
|
532
|
+
brain diff show [from_ref] [to_ref]
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
### Default Behavior
|
|
538
|
+
|
|
539
|
+
If no refs provided:
|
|
540
|
+
|
|
541
|
+
```bash
|
|
542
|
+
brain diff show
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
Equivalent to:
|
|
546
|
+
|
|
547
|
+
```bash
|
|
548
|
+
brain diff show HEAD~1 HEAD
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
### Git Reference Explanation
|
|
554
|
+
|
|
555
|
+
| Ref | Meaning |
|
|
556
|
+
| ------ | --------------------- |
|
|
557
|
+
| HEAD | current commit |
|
|
558
|
+
| HEAD~1 | previous commit |
|
|
559
|
+
| HEAD~5 | 5 commits before HEAD |
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
### Internal Workflow
|
|
564
|
+
|
|
565
|
+
project-brain:
|
|
566
|
+
|
|
567
|
+
1. validates git refs
|
|
568
|
+
2. runs git diff logic
|
|
569
|
+
3. computes changed files
|
|
570
|
+
4. extracts Python functions
|
|
571
|
+
5. compares function bodies
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
|
|
575
|
+
### Output Example
|
|
576
|
+
|
|
577
|
+
```text
|
|
578
|
+
Files Changed: 2
|
|
579
|
+
|
|
580
|
+
Modified:
|
|
581
|
+
* src/api.py
|
|
582
|
+
|
|
583
|
+
Added:
|
|
584
|
+
* src/utils.py
|
|
585
|
+
|
|
586
|
+
Deleted:
|
|
587
|
+
* src/legacy.py
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
### Function-Level Output
|
|
593
|
+
|
|
594
|
+
```text
|
|
595
|
+
Functions Added:
|
|
596
|
+
* validate_user
|
|
597
|
+
|
|
598
|
+
Functions Modified:
|
|
599
|
+
* create_user
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
### Edge Cases
|
|
605
|
+
|
|
606
|
+
* non-Python files only receive file-level diff
|
|
607
|
+
* invalid git refs fail safely
|
|
608
|
+
* non-git repositories rejected
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
## `brain diff review`
|
|
613
|
+
|
|
614
|
+
Generate semantic diff explanations.
|
|
615
|
+
|
|
616
|
+
### Syntax
|
|
617
|
+
|
|
618
|
+
```bash
|
|
619
|
+
brain diff review [from_ref] [to_ref]
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
### What It Does
|
|
625
|
+
|
|
626
|
+
* computes git diff
|
|
627
|
+
* extracts changed functions
|
|
628
|
+
* builds prompts
|
|
629
|
+
* calls LLM provider
|
|
630
|
+
* caches results
|
|
631
|
+
* generates reports
|
|
632
|
+
|
|
633
|
+
---
|
|
634
|
+
|
|
635
|
+
### Outputs
|
|
636
|
+
|
|
637
|
+
```text
|
|
638
|
+
.brain/reports/diff_<timestamp>.json
|
|
639
|
+
.brain/reports/diff_<timestamp>.html
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
---
|
|
643
|
+
|
|
644
|
+
### HTML Report
|
|
645
|
+
|
|
646
|
+
Interactive HTML report includes:
|
|
647
|
+
|
|
648
|
+
* grouped files
|
|
649
|
+
* risk labels
|
|
650
|
+
* semantic summaries
|
|
651
|
+
* impact descriptions
|
|
652
|
+
|
|
653
|
+
---
|
|
654
|
+
|
|
655
|
+
### LLM Disabled Mode
|
|
656
|
+
|
|
657
|
+
If:
|
|
658
|
+
|
|
659
|
+
```yaml
|
|
660
|
+
provider: none
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
project-brain generates fallback heuristic summaries.
|
|
664
|
+
|
|
665
|
+
---
|
|
666
|
+
|
|
667
|
+
## `brain diff explain`
|
|
668
|
+
|
|
669
|
+
Explain a file or function.
|
|
670
|
+
|
|
671
|
+
### Syntax
|
|
672
|
+
|
|
673
|
+
```bash
|
|
674
|
+
brain diff explain <target>
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
---
|
|
678
|
+
|
|
679
|
+
### File Example
|
|
680
|
+
|
|
681
|
+
```bash
|
|
682
|
+
brain diff explain src/api.py
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
---
|
|
686
|
+
|
|
687
|
+
### Function Example
|
|
688
|
+
|
|
689
|
+
```bash
|
|
690
|
+
brain diff explain src/api.py:create_user
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
---
|
|
694
|
+
|
|
695
|
+
### Behavior
|
|
696
|
+
|
|
697
|
+
Without LLM:
|
|
698
|
+
|
|
699
|
+
* structural summary only
|
|
700
|
+
|
|
701
|
+
With LLM:
|
|
702
|
+
|
|
703
|
+
* semantic explanation
|
|
704
|
+
* risks
|
|
705
|
+
* logic overview
|
|
706
|
+
|
|
707
|
+
---
|
|
708
|
+
|
|
709
|
+
# ๐ฆ Export Commands
|
|
710
|
+
|
|
711
|
+
---
|
|
712
|
+
|
|
713
|
+
## `brain export full_code`
|
|
714
|
+
|
|
715
|
+
Export entire repository.
|
|
716
|
+
|
|
717
|
+
### Syntax
|
|
718
|
+
|
|
719
|
+
```bash
|
|
720
|
+
brain export full_code
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
---
|
|
724
|
+
|
|
725
|
+
### Output
|
|
726
|
+
|
|
727
|
+
```text
|
|
728
|
+
.brain/exports/full_code.txt
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
---
|
|
732
|
+
|
|
733
|
+
### Export Format
|
|
734
|
+
|
|
735
|
+
```text
|
|
736
|
+
=== FILE: src/api.py ===
|
|
737
|
+
<content>
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
---
|
|
741
|
+
|
|
742
|
+
### Behavior
|
|
743
|
+
|
|
744
|
+
* recursively scans files
|
|
745
|
+
* respects ignore rules
|
|
746
|
+
* respects file size limits
|
|
747
|
+
* optionally skips tests
|
|
748
|
+
|
|
749
|
+
---
|
|
750
|
+
|
|
751
|
+
## `brain export file`
|
|
752
|
+
|
|
753
|
+
Manually export single file.
|
|
754
|
+
|
|
755
|
+
### Syntax
|
|
756
|
+
|
|
757
|
+
```bash
|
|
758
|
+
brain export file <path>
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
---
|
|
762
|
+
|
|
763
|
+
### Example
|
|
764
|
+
|
|
765
|
+
```bash
|
|
766
|
+
brain export file src/api.py
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
---
|
|
770
|
+
|
|
771
|
+
## `brain export dir`
|
|
772
|
+
|
|
773
|
+
Manually export directory.
|
|
774
|
+
|
|
775
|
+
### Syntax
|
|
776
|
+
|
|
777
|
+
```bash
|
|
778
|
+
brain export dir <path>
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
---
|
|
782
|
+
|
|
783
|
+
### Example
|
|
784
|
+
|
|
785
|
+
```bash
|
|
786
|
+
brain export dir src/
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
---
|
|
790
|
+
|
|
791
|
+
## `brain export code_changes`
|
|
792
|
+
|
|
793
|
+
Export changed code between refs.
|
|
794
|
+
|
|
795
|
+
### Syntax
|
|
796
|
+
|
|
797
|
+
```bash
|
|
798
|
+
brain export code_changes <from_ref> <to_ref>
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
---
|
|
802
|
+
|
|
803
|
+
### Example
|
|
804
|
+
|
|
805
|
+
```bash
|
|
806
|
+
brain export code_changes HEAD~3 HEAD
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
---
|
|
810
|
+
|
|
811
|
+
### Output
|
|
812
|
+
|
|
813
|
+
```text
|
|
814
|
+
=== FILE: src/api.py ===
|
|
815
|
+
|
|
816
|
+
--- FUNCTION: create_user (UPDATED) ---
|
|
817
|
+
OLD:
|
|
818
|
+
...
|
|
819
|
+
|
|
820
|
+
NEW:
|
|
821
|
+
...
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
---
|
|
825
|
+
|
|
826
|
+
# ๐งช LLM Commands
|
|
827
|
+
|
|
828
|
+
---
|
|
829
|
+
|
|
830
|
+
## `brain testllm test`
|
|
831
|
+
|
|
832
|
+
Test provider connectivity.
|
|
833
|
+
|
|
834
|
+
### Syntax
|
|
835
|
+
|
|
836
|
+
```bash
|
|
837
|
+
brain testllm test
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
---
|
|
841
|
+
|
|
842
|
+
### What It Does
|
|
843
|
+
|
|
844
|
+
* loads provider config
|
|
845
|
+
* sends test prompt
|
|
846
|
+
* validates response
|
|
847
|
+
* optionally fetches model list
|
|
848
|
+
|
|
849
|
+
---
|
|
850
|
+
|
|
851
|
+
### Disabled Mode
|
|
852
|
+
|
|
853
|
+
If:
|
|
854
|
+
|
|
855
|
+
```yaml
|
|
856
|
+
provider: none
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
Output:
|
|
860
|
+
|
|
861
|
+
```text
|
|
862
|
+
LLM disabled
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
---
|
|
866
|
+
|
|
867
|
+
# โ๏ธ Configuration
|
|
868
|
+
|
|
869
|
+
Configuration file:
|
|
870
|
+
|
|
871
|
+
```text
|
|
872
|
+
brain.yaml
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
---
|
|
876
|
+
|
|
877
|
+
# Example Configuration
|
|
878
|
+
|
|
879
|
+
```yaml
|
|
880
|
+
version: "1.0"
|
|
881
|
+
|
|
882
|
+
llm:
|
|
883
|
+
provider: none
|
|
884
|
+
model: ""
|
|
885
|
+
timeout_sec: 60
|
|
886
|
+
|
|
887
|
+
analysis:
|
|
888
|
+
depth: fast
|
|
889
|
+
include_tests: false
|
|
890
|
+
ignore:
|
|
891
|
+
- .brain/
|
|
892
|
+
- .git/
|
|
893
|
+
- node_modules/
|
|
894
|
+
|
|
895
|
+
diff:
|
|
896
|
+
mode: function
|
|
897
|
+
|
|
898
|
+
export:
|
|
899
|
+
full_code:
|
|
900
|
+
include_tests: false
|
|
901
|
+
max_file_size_kb: 200
|
|
902
|
+
|
|
903
|
+
manual_add:
|
|
904
|
+
allow_duplicates: true
|
|
905
|
+
|
|
906
|
+
changes:
|
|
907
|
+
mode: function
|
|
908
|
+
include_context: true
|
|
909
|
+
output_path: .brain/exports/code_changes.txt
|
|
910
|
+
|
|
911
|
+
explain:
|
|
912
|
+
level: detailed
|
|
913
|
+
include_risks: true
|
|
914
|
+
|
|
915
|
+
output:
|
|
916
|
+
format: text
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
---
|
|
920
|
+
|
|
921
|
+
# ๐ API Key Setup
|
|
922
|
+
|
|
923
|
+
Secrets should NEVER be stored inside `brain.yaml`.
|
|
924
|
+
|
|
925
|
+
---
|
|
926
|
+
|
|
927
|
+
## Windows CMD
|
|
928
|
+
|
|
929
|
+
```bash
|
|
930
|
+
setx OPENAI_API_KEY "your_key"
|
|
931
|
+
```
|
|
932
|
+
|
|
933
|
+
```bash
|
|
934
|
+
setx GEMINI_API_KEY "your_key"
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
```bash
|
|
938
|
+
setx HUGGINGFACE_API_KEY "your_key"
|
|
939
|
+
```
|
|
940
|
+
|
|
941
|
+
---
|
|
942
|
+
|
|
943
|
+
## PowerShell
|
|
944
|
+
|
|
945
|
+
```powershell
|
|
946
|
+
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY","your_key","User")
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
---
|
|
950
|
+
|
|
951
|
+
## Linux/macOS
|
|
952
|
+
|
|
953
|
+
```bash
|
|
954
|
+
export OPENAI_API_KEY="your_key"
|
|
955
|
+
```
|
|
956
|
+
|
|
957
|
+
---
|
|
958
|
+
|
|
959
|
+
# ๐ด Offline Mode
|
|
960
|
+
|
|
961
|
+
project-brain fully supports offline workflows.
|
|
962
|
+
|
|
963
|
+
Use:
|
|
964
|
+
|
|
965
|
+
```yaml
|
|
966
|
+
llm:
|
|
967
|
+
provider: none
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
Behavior:
|
|
971
|
+
|
|
972
|
+
* no API calls
|
|
973
|
+
* no cloud dependency
|
|
974
|
+
* local-only analysis
|
|
975
|
+
* fallback explanations enabled
|
|
976
|
+
|
|
977
|
+
---
|
|
978
|
+
|
|
979
|
+
# ๐ Example Outputs
|
|
980
|
+
|
|
981
|
+
---
|
|
982
|
+
|
|
983
|
+
## Analysis
|
|
984
|
+
|
|
985
|
+
```text
|
|
986
|
+
๐ Analyzing: .
|
|
987
|
+
|
|
988
|
+
๐ File Paths:
|
|
989
|
+
src/api.py
|
|
990
|
+
src/utils.py
|
|
991
|
+
|
|
992
|
+
โ
Analysis complete
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
---
|
|
996
|
+
|
|
997
|
+
## Diff Review
|
|
998
|
+
|
|
999
|
+
```text
|
|
1000
|
+
Function: create_user
|
|
1001
|
+
|
|
1002
|
+
Change:
|
|
1003
|
+
Added validation layer
|
|
1004
|
+
|
|
1005
|
+
Impact:
|
|
1006
|
+
Improves input integrity
|
|
1007
|
+
|
|
1008
|
+
Risk:
|
|
1009
|
+
medium
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
---
|
|
1013
|
+
|
|
1014
|
+
# ๐ Project Structure
|
|
1015
|
+
|
|
1016
|
+
```text
|
|
1017
|
+
project-brain/
|
|
1018
|
+
โ
|
|
1019
|
+
โโโ src/
|
|
1020
|
+
โ โโโ project_brain/
|
|
1021
|
+
โ โโโ cli.py
|
|
1022
|
+
โ โโโ core/
|
|
1023
|
+
โ โโโ llm/
|
|
1024
|
+
โ โโโ storage/
|
|
1025
|
+
โ โโโ config/
|
|
1026
|
+
โ
|
|
1027
|
+
โโโ tests/
|
|
1028
|
+
โโโ brain.yaml
|
|
1029
|
+
โโโ pyproject.toml
|
|
1030
|
+
โโโ README.md
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
---
|
|
1034
|
+
|
|
1035
|
+
# ๐ชต Logging System
|
|
1036
|
+
|
|
1037
|
+
Logs stored inside:
|
|
1038
|
+
|
|
1039
|
+
```text
|
|
1040
|
+
.brain/logs.txt
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
Tracks:
|
|
1044
|
+
|
|
1045
|
+
* warnings
|
|
1046
|
+
* provider failures
|
|
1047
|
+
* parsing errors
|
|
1048
|
+
* export failures
|
|
1049
|
+
* cache issues
|
|
1050
|
+
|
|
1051
|
+
Logging failures never crash the CLI.
|
|
1052
|
+
|
|
1053
|
+
---
|
|
1054
|
+
|
|
1055
|
+
# ๐ ๏ธ Troubleshooting
|
|
1056
|
+
|
|
1057
|
+
---
|
|
1058
|
+
|
|
1059
|
+
## โ Not a git repository
|
|
1060
|
+
|
|
1061
|
+
Initialize git:
|
|
1062
|
+
|
|
1063
|
+
```bash
|
|
1064
|
+
git init
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
---
|
|
1068
|
+
|
|
1069
|
+
## โ Invalid git reference
|
|
1070
|
+
|
|
1071
|
+
Check refs:
|
|
1072
|
+
|
|
1073
|
+
```bash
|
|
1074
|
+
git log --oneline
|
|
1075
|
+
```
|
|
1076
|
+
|
|
1077
|
+
---
|
|
1078
|
+
|
|
1079
|
+
## โ Empty export
|
|
1080
|
+
|
|
1081
|
+
Possible causes:
|
|
1082
|
+
|
|
1083
|
+
* ignored paths
|
|
1084
|
+
* file size limits
|
|
1085
|
+
* tests excluded
|
|
1086
|
+
|
|
1087
|
+
---
|
|
1088
|
+
|
|
1089
|
+
## โ Provider failures
|
|
1090
|
+
|
|
1091
|
+
Check:
|
|
1092
|
+
|
|
1093
|
+
* API keys
|
|
1094
|
+
* internet connectivity
|
|
1095
|
+
* provider model name
|
|
1096
|
+
|
|
1097
|
+
---
|
|
1098
|
+
|
|
1099
|
+
## โ Missing API key
|
|
1100
|
+
|
|
1101
|
+
Verify environment variable:
|
|
1102
|
+
|
|
1103
|
+
```bash
|
|
1104
|
+
echo %OPENAI_API_KEY%
|
|
1105
|
+
```
|
|
1106
|
+
|
|
1107
|
+
---
|
|
1108
|
+
|
|
1109
|
+
# ๐งช Testing & QA
|
|
1110
|
+
|
|
1111
|
+
Current QA status:
|
|
1112
|
+
|
|
1113
|
+
* 18 automated tests passing
|
|
1114
|
+
* export validation
|
|
1115
|
+
* function diff validation
|
|
1116
|
+
* config validation
|
|
1117
|
+
* edge-case handling
|
|
1118
|
+
* provider fallback testing
|
|
1119
|
+
|
|
1120
|
+
---
|
|
1121
|
+
|
|
1122
|
+
# ๐ฎ Roadmap
|
|
1123
|
+
|
|
1124
|
+
## Near-Term
|
|
1125
|
+
|
|
1126
|
+
* semantic diff intelligence
|
|
1127
|
+
* integration tests
|
|
1128
|
+
* incremental analysis
|
|
1129
|
+
* performance improvements
|
|
1130
|
+
* rename detection
|
|
1131
|
+
|
|
1132
|
+
---
|
|
1133
|
+
|
|
1134
|
+
## Mid-Term
|
|
1135
|
+
|
|
1136
|
+
* multi-language parsing
|
|
1137
|
+
* plugin architecture
|
|
1138
|
+
* dependency graphing
|
|
1139
|
+
* richer semantic indexing
|
|
1140
|
+
|
|
1141
|
+
---
|
|
1142
|
+
|
|
1143
|
+
# ๐ Security & Privacy
|
|
1144
|
+
|
|
1145
|
+
project-brain is designed with a local-first philosophy.
|
|
1146
|
+
|
|
1147
|
+
Key principles:
|
|
1148
|
+
|
|
1149
|
+
* no automatic code uploads
|
|
1150
|
+
* offline workflows supported
|
|
1151
|
+
* API keys via environment variables only
|
|
1152
|
+
* repository data stored locally
|
|
1153
|
+
|
|
1154
|
+
LLM usage is fully optional.
|
|
1155
|
+
|
|
1156
|
+
---
|
|
1157
|
+
|
|
1158
|
+
# ๐ค Contributing
|
|
1159
|
+
|
|
1160
|
+
Contributions are welcome.
|
|
1161
|
+
|
|
1162
|
+
Recommended workflow:
|
|
1163
|
+
|
|
1164
|
+
```bash
|
|
1165
|
+
git checkout -b feature/my-feature
|
|
1166
|
+
```
|
|
1167
|
+
|
|
1168
|
+
Guidelines:
|
|
1169
|
+
|
|
1170
|
+
* keep PRs focused
|
|
1171
|
+
* preserve CLI consistency
|
|
1172
|
+
* add tests for new logic
|
|
1173
|
+
* avoid unnecessary dependencies
|
|
1174
|
+
|
|
1175
|
+
---
|
|
1176
|
+
|
|
1177
|
+
# ๐ License
|
|
1178
|
+
|
|
1179
|
+
MIT License
|
|
1180
|
+
|
|
1181
|
+
---
|
|
1182
|
+
|
|
1183
|
+
# ๐ง Final Positioning
|
|
1184
|
+
|
|
1185
|
+
> project-brain is a local-first developer intelligence CLI that transforms repositories and Git diffs into structured, explainable engineering context.
|