codescope-ai 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.
- codescope_ai-0.1.0/.gitignore +36 -0
- codescope_ai-0.1.0/CHANGELOG.md +24 -0
- codescope_ai-0.1.0/EVALUATION.md +139 -0
- codescope_ai-0.1.0/LICENSE +21 -0
- codescope_ai-0.1.0/PKG-INFO +214 -0
- codescope_ai-0.1.0/README.md +172 -0
- codescope_ai-0.1.0/evals/library/project/.codescope.toml +9 -0
- codescope_ai-0.1.0/evals/library/project/README.md +13 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/README.md +63 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/architecture.md +46 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.api.md +26 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.catalog.md +30 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.fines.md +39 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.loans.md +37 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.md +11 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.models.md +44 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.notifications.md +34 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.reports.md +27 -0
- codescope_ai-0.1.0/evals/library/project/docs/codescope/modules/library.storage.md +26 -0
- codescope_ai-0.1.0/evals/library/project/library/__init__.py +1 -0
- codescope_ai-0.1.0/evals/library/project/library/api.py +39 -0
- codescope_ai-0.1.0/evals/library/project/library/catalog.py +35 -0
- codescope_ai-0.1.0/evals/library/project/library/fines.py +41 -0
- codescope_ai-0.1.0/evals/library/project/library/loans.py +59 -0
- codescope_ai-0.1.0/evals/library/project/library/models.py +46 -0
- codescope_ai-0.1.0/evals/library/project/library/notifications.py +44 -0
- codescope_ai-0.1.0/evals/library/project/library/reports.py +24 -0
- codescope_ai-0.1.0/evals/library/project/library/storage.py +31 -0
- codescope_ai-0.1.0/evals/library/project/tests/test_fines.py +17 -0
- codescope_ai-0.1.0/evals/library/project/tests/test_loans.py +42 -0
- codescope_ai-0.1.0/evals/library/results/2026-10-18-static.md +55 -0
- codescope_ai-0.1.0/evals/library/results/2026-10-27-static.md +55 -0
- codescope_ai-0.1.0/evals/library/results/2026-10-31-ai.md +76 -0
- codescope_ai-0.1.0/evals/library/results/2026-11-21-agent.md +50 -0
- codescope_ai-0.1.0/evals/library/results/2026-11-21-ai.md +76 -0
- codescope_ai-0.1.0/evals/library/suite.toml +190 -0
- codescope_ai-0.1.0/pyproject.toml +92 -0
- codescope_ai-0.1.0/src/codescope/__init__.py +3 -0
- codescope_ai-0.1.0/src/codescope/__main__.py +3 -0
- codescope_ai-0.1.0/src/codescope/ai/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/ai/agent.py +191 -0
- codescope_ai-0.1.0/src/codescope/ai/answer.py +89 -0
- codescope_ai-0.1.0/src/codescope/ai/redact.py +54 -0
- codescope_ai-0.1.0/src/codescope/ai/reviewer.py +187 -0
- codescope_ai-0.1.0/src/codescope/ai/schemas.py +69 -0
- codescope_ai-0.1.0/src/codescope/ai/summarizer.py +388 -0
- codescope_ai-0.1.0/src/codescope/cli.py +605 -0
- codescope_ai-0.1.0/src/codescope/config.py +192 -0
- codescope_ai-0.1.0/src/codescope/docs/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/docs/writer.py +432 -0
- codescope_ai-0.1.0/src/codescope/evaluation/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/evaluation/report.py +252 -0
- codescope_ai-0.1.0/src/codescope/evaluation/runner.py +296 -0
- codescope_ai-0.1.0/src/codescope/gitutils.py +92 -0
- codescope_ai-0.1.0/src/codescope/graph/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/graph/components.py +25 -0
- codescope_ai-0.1.0/src/codescope/graph/model.py +81 -0
- codescope_ai-0.1.0/src/codescope/graph/modules.py +61 -0
- codescope_ai-0.1.0/src/codescope/graph/resolver.py +349 -0
- codescope_ai-0.1.0/src/codescope/index/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/index/builder.py +81 -0
- codescope_ai-0.1.0/src/codescope/index/chunker.py +164 -0
- codescope_ai-0.1.0/src/codescope/index/search.py +144 -0
- codescope_ai-0.1.0/src/codescope/llm/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/llm/base.py +108 -0
- codescope_ai-0.1.0/src/codescope/llm/client.py +164 -0
- codescope_ai-0.1.0/src/codescope/llm/gemini.py +216 -0
- codescope_ai-0.1.0/src/codescope/llm/ratelimit.py +43 -0
- codescope_ai-0.1.0/src/codescope/mcp_server.py +147 -0
- codescope_ai-0.1.0/src/codescope/models.py +137 -0
- codescope_ai-0.1.0/src/codescope/parsing/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/parsing/python.py +246 -0
- codescope_ai-0.1.0/src/codescope/pipeline.py +145 -0
- codescope_ai-0.1.0/src/codescope/review/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/review/analysis.py +292 -0
- codescope_ai-0.1.0/src/codescope/review/diff.py +100 -0
- codescope_ai-0.1.0/src/codescope/review/run.py +118 -0
- codescope_ai-0.1.0/src/codescope/scanner/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/scanner/files.py +156 -0
- codescope_ai-0.1.0/src/codescope/storage/__init__.py +0 -0
- codescope_ai-0.1.0/src/codescope/storage/db.py +519 -0
- codescope_ai-0.1.0/src/codescope/templates/architecture.md.j2 +38 -0
- codescope_ai-0.1.0/src/codescope/templates/module.md.j2 +94 -0
- codescope_ai-0.1.0/src/codescope/templates/overview.md.j2 +100 -0
- codescope_ai-0.1.0/src/codescope/templates/prompts/agent.j2 +13 -0
- codescope_ai-0.1.0/src/codescope/templates/prompts/ask.j2 +15 -0
- codescope_ai-0.1.0/src/codescope/templates/prompts/component_summary.j2 +8 -0
- codescope_ai-0.1.0/src/codescope/templates/prompts/file_summary.j2 +19 -0
- codescope_ai-0.1.0/src/codescope/templates/prompts/project_summary.j2 +15 -0
- codescope_ai-0.1.0/src/codescope/templates/prompts/review.j2 +40 -0
- codescope_ai-0.1.0/src/codescope/templates/prompts/system.j2 +8 -0
- codescope_ai-0.1.0/src/codescope/templates/review.md.j2 +113 -0
- codescope_ai-0.1.0/src/codescope/tools.py +114 -0
- codescope_ai-0.1.0/tests/conftest.py +18 -0
- codescope_ai-0.1.0/tests/fakes.py +150 -0
- codescope_ai-0.1.0/tests/fixtures/sample_project/cli.py +9 -0
- codescope_ai-0.1.0/tests/fixtures/sample_project/shop/__init__.py +5 -0
- codescope_ai-0.1.0/tests/fixtures/sample_project/shop/models.py +25 -0
- codescope_ai-0.1.0/tests/fixtures/sample_project/shop/services.py +21 -0
- codescope_ai-0.1.0/tests/fixtures/sample_project/shop/utils.py +6 -0
- codescope_ai-0.1.0/tests/fixtures/sample_project/tests/test_services.py +5 -0
- codescope_ai-0.1.0/tests/test_agent.py +120 -0
- codescope_ai-0.1.0/tests/test_ai_summaries.py +132 -0
- codescope_ai-0.1.0/tests/test_django_patterns.py +150 -0
- codescope_ai-0.1.0/tests/test_evaluation.py +149 -0
- codescope_ai-0.1.0/tests/test_github_files.py +53 -0
- codescope_ai-0.1.0/tests/test_llm_layer.py +199 -0
- codescope_ai-0.1.0/tests/test_mcp_server.py +119 -0
- codescope_ai-0.1.0/tests/test_modules_and_files.py +77 -0
- codescope_ai-0.1.0/tests/test_python_parser.py +133 -0
- codescope_ai-0.1.0/tests/test_resolver.py +83 -0
- codescope_ai-0.1.0/tests/test_review.py +163 -0
- codescope_ai-0.1.0/tests/test_scan_and_docs.py +160 -0
- codescope_ai-0.1.0/tests/test_search_and_ask.py +136 -0
- codescope_ai-0.1.0/tests/test_tools.py +66 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
|
|
10
|
+
# Tooling caches
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
.ruff_cache/
|
|
14
|
+
.coverage
|
|
15
|
+
htmlcov/
|
|
16
|
+
|
|
17
|
+
# CodeScope local knowledge base
|
|
18
|
+
.codescope/
|
|
19
|
+
|
|
20
|
+
# Editors and OS
|
|
21
|
+
.vscode/
|
|
22
|
+
.idea/
|
|
23
|
+
*.code-workspace
|
|
24
|
+
.~lock.*#
|
|
25
|
+
.DS_Store
|
|
26
|
+
|
|
27
|
+
# Secrets
|
|
28
|
+
.env
|
|
29
|
+
.env.*
|
|
30
|
+
|
|
31
|
+
# Personal learning exercises, except the code map, which is shared
|
|
32
|
+
learning/*
|
|
33
|
+
!learning/codebase-map.html
|
|
34
|
+
|
|
35
|
+
# Personal Claude Code instructions
|
|
36
|
+
CLAUDE.local.md
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (first release)
|
|
4
|
+
|
|
5
|
+
CodeScope reads a Python codebase, works out how its parts depend on each other, and explains it.
|
|
6
|
+
|
|
7
|
+
- `codescope scan` / `update`: parses the code with tree-sitter, builds a dependency graph with
|
|
8
|
+
a confidence for every link, and writes Markdown docs where every name links to its source
|
|
9
|
+
lines. Only changed files are redone.
|
|
10
|
+
- AI summaries with Google Gemini (optional): files, then components, then the project.
|
|
11
|
+
Secrets are removed before anything is sent.
|
|
12
|
+
- `codescope ask`: answers with citations to the exact source lines (RAG: keyword and meaning
|
|
13
|
+
search, graph expansion, citation checks). An honest "not found" when the code has no answer.
|
|
14
|
+
- `codescope ask --agent`: the AI searches and reads the code step by step, with the same
|
|
15
|
+
citation checks, a step limit and the cost shown.
|
|
16
|
+
- `codescope review`: changed functions, the code they affect, the tests to run, and AI
|
|
17
|
+
findings checked against the changed lines.
|
|
18
|
+
- `codescope mcp`: CodeScope's tools (`find_callers`, `find_dependencies`, `search_code`,
|
|
19
|
+
`read_code`) for Claude Code, Cursor and VS Code. No API key needed.
|
|
20
|
+
Install with `pip install "codescope-ai[mcp]"`.
|
|
21
|
+
- `codescope inspect`, `codescope eval` (also `--agent`), and a GitHub Action for pull-request
|
|
22
|
+
reviews and docs updates.
|
|
23
|
+
|
|
24
|
+
Measured accuracy and its limits: [EVALUATION.md](https://github.com/kushpatel2012/codescope/blob/main/EVALUATION.md).
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Evaluation
|
|
2
|
+
|
|
3
|
+
How accurate CodeScope is, measured on a suite with known answers. Every number here can be
|
|
4
|
+
reproduced with one command, and results are only added after a real run.
|
|
5
|
+
|
|
6
|
+
## The suite: `evals/library`
|
|
7
|
+
|
|
8
|
+
A small lending-library project (380 lines: books, members, loans, fines, notifications,
|
|
9
|
+
reports, storage, request handlers, and 7 tests), written for this evaluation:
|
|
10
|
+
|
|
11
|
+
- **21 questions**: 16 whose answer is in the code, with the symbols that answer them, and
|
|
12
|
+
5 that the code cannot answer (payment gateway, OAuth, migrations...).
|
|
13
|
+
- **10 changes**: 8 planted bugs (off-by-one errors, an inverted `min`/`max`, a removed line,
|
|
14
|
+
a broken signature, `eval` on user input) and 2 harmless changes (a renamed variable, an
|
|
15
|
+
added docstring). Each lists the changed code, affected code and tests a review should find.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
codescope eval evals/library --no-llm # static analysis and keyword search: free
|
|
19
|
+
codescope eval evals/library # everything, with AI (about 55 Gemini requests)
|
|
20
|
+
codescope eval evals/library --agent # the questions, answered by `ask --agent` (about 90)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Each run writes a full report, with per-question and per-change results, to
|
|
24
|
+
`evals/library/results/`.
|
|
25
|
+
|
|
26
|
+
## Results
|
|
27
|
+
|
|
28
|
+
### Without AI (2026-10-18)
|
|
29
|
+
|
|
30
|
+
| Measure | Result |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| Retrieval, keyword only: answer in top 5 | 15/16 (94%) |
|
|
33
|
+
| Retrieval, keyword only: answer in the context given to the model (with graph expansion) | 16/16 (100%) |
|
|
34
|
+
| Retrieval, keyword only: mean reciprocal rank | 0.65 |
|
|
35
|
+
| Review: changed code identified | 10/10 (100%) |
|
|
36
|
+
| Review: affected code identified | 5/5 (100%) |
|
|
37
|
+
| Review: tests to run identified | 7/7 (100%) |
|
|
38
|
+
|
|
39
|
+
Full report: [evals/library/results/2026-10-18-static.md](evals/library/results/2026-10-18-static.md)
|
|
40
|
+
|
|
41
|
+
### With AI (2026-10-31, `gemini-3.5-flash-lite` for everything, `gemini-embedding-001`)
|
|
42
|
+
|
|
43
|
+
| Measure | Result |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| Retrieval, hybrid (keyword + embeddings): answer in top 5 | 16/16 (100%), keyword only: 15/16 |
|
|
46
|
+
| Retrieval, hybrid: mean reciprocal rank | 0.72, keyword only: 0.65 |
|
|
47
|
+
| Answers that cite the code that answers the question | 16/16 (100%) |
|
|
48
|
+
| Unanswerable questions reported as "not found" | 5/5 (100%) |
|
|
49
|
+
| Planted bugs caught by the AI review | 8/8 (100%) |
|
|
50
|
+
| Harmless changes with no findings (no false alarms) | 2/2 (100%) |
|
|
51
|
+
| AI requests that failed | 0/31 |
|
|
52
|
+
|
|
53
|
+
Cost: 53 requests, 39,203 tokens in, 2,886 out, 5 minutes (mostly waiting for the
|
|
54
|
+
free-tier rate limit).
|
|
55
|
+
|
|
56
|
+
Meaning search helped most where the question and the code use different words: "How is
|
|
57
|
+
the due date of a new loan set?" moved from rank 7 (keyword) to 4 (hybrid), and "What is the
|
|
58
|
+
maximum fine a member can be charged?" from 3 to 1.
|
|
59
|
+
|
|
60
|
+
Every planted bug got a finding that names the actual problem, not just a finding near the
|
|
61
|
+
line, for example "Incorrect fine calculation logic using max instead of min" and "Use of
|
|
62
|
+
eval() on user input".
|
|
63
|
+
|
|
64
|
+
Full report: [evals/library/results/2026-10-31-ai.md](evals/library/results/2026-10-31-ai.md)
|
|
65
|
+
|
|
66
|
+
These are one run of one model. In a separate one-off test outside the suite (an
|
|
67
|
+
off-by-one and a `- 1` in a fine calculation), `gemini-flash-lite-latest` missed both bugs and
|
|
68
|
+
`gemini-flash-latest` found both, so results depend on the model and vary between runs.
|
|
69
|
+
|
|
70
|
+
A second run on 2026-11-21, with the same model, code and suite, caught **6/8** planted bugs
|
|
71
|
+
instead of 8/8: it missed `loan-limit-off-by-one` and `renewal-limit`, both one-character
|
|
72
|
+
changes to a comparison. Everything else matched. So the AI review score is a range, 6-8 of 8,
|
|
73
|
+
not a single number; with 8 bugs, one catch more or less moves it by 12 points.
|
|
74
|
+
|
|
75
|
+
### RAG vs agent (2026-11-21, `gemini-3.5-flash-lite`)
|
|
76
|
+
|
|
77
|
+
The same 21 questions, the same model, scored by the same rules, answered by `ask` (one
|
|
78
|
+
search, then an answer) and by `ask --agent` (the model searches and reads, step by step).
|
|
79
|
+
|
|
80
|
+
| Measure | RAG (`ask`) | Agent (`ask --agent`) |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| The code that answers the question was found | 16/16 (hybrid top 5) | 16/16 (read by the agent) |
|
|
83
|
+
| Answers that cite the code that answers the question | 16/16 | 16/16 |
|
|
84
|
+
| Unanswerable questions reported as "not found" | 5/5 | 5/5 |
|
|
85
|
+
| AI requests per question (embeddings included) | 2.0 | 4.1 |
|
|
86
|
+
| Tokens sent | 39,203 for 21 questions **and** 10 reviews | 57,104 for 21 questions |
|
|
87
|
+
|
|
88
|
+
On this suite the agent is as accurate as RAG and costs about twice the requests and more
|
|
89
|
+
than twice the tokens per question: every agent step sends the whole conversation again,
|
|
90
|
+
including earlier search results. It worked hardest where search is weakest ("How is the due
|
|
91
|
+
date of a new loan set?", keyword rank 7: 7 requests) and on questions with no answer
|
|
92
|
+
(5 requests each, against 2 for RAG), because it keeps searching before it gives up.
|
|
93
|
+
|
|
94
|
+
The suite's project is small (27 chunks), so RAG's top 8 sources already contain every
|
|
95
|
+
answer; there is nothing left for the agent to find. The agent should pay off on larger
|
|
96
|
+
projects where the answer is spread over code that one search does not rank highly. This
|
|
97
|
+
suite cannot show that; a larger suite is needed.
|
|
98
|
+
|
|
99
|
+
Full reports: [RAG](evals/library/results/2026-11-21-ai.md),
|
|
100
|
+
[agent](evals/library/results/2026-11-21-agent.md)
|
|
101
|
+
|
|
102
|
+
## What the evaluation found and fixed
|
|
103
|
+
|
|
104
|
+
The first run scored 5/16 on retrieval. Two causes:
|
|
105
|
+
|
|
106
|
+
1. **A scoring bug.** Short classes are one search chunk, so a question about
|
|
107
|
+
`Catalog.search` was answered by the `Catalog` chunk, but the scorer only accepted a chunk
|
|
108
|
+
named exactly `Catalog.search`. Fixed in the scorer.
|
|
109
|
+
2. **A real search weakness.** Word stemming handled "-ing" and "-s" but not "-ed", so
|
|
110
|
+
"renewed" did not match `renew`. Fixed in the search.
|
|
111
|
+
|
|
112
|
+
The first runs with AI scored 0 bugs caught and 10/16 answers. The cause was not the model:
|
|
113
|
+
**the eval hid failed AI requests.** A request that failed (daily free-tier quota used up,
|
|
114
|
+
network down, model overloaded) was reported as "missed" or "not found", the same as a wrong
|
|
115
|
+
answer. Failed requests are now shown as errors, counted separately, and left out of the AI
|
|
116
|
+
scores, and a test checks this.
|
|
117
|
+
|
|
118
|
+
Free-tier limits matter: on the key used here, the Flash models allow 5 requests per minute
|
|
119
|
+
and 20 per day, fewer than one full run needs (31 generation requests), while Flash Lite
|
|
120
|
+
allows 15 per minute and 500 per day. The suite's model is fixed in
|
|
121
|
+
`evals/library/project/.codescope.toml` so results from different days are comparable.
|
|
122
|
+
|
|
123
|
+
## Limits of this evaluation
|
|
124
|
+
|
|
125
|
+
- **Small and self-written.** The suite was written alongside CodeScope, by the same author,
|
|
126
|
+
so it may favour how CodeScope works. Results on large, unfamiliar codebases will be lower.
|
|
127
|
+
- **One fix was made after seeing the suite** (the "-ed" stemming). The rule is general, but
|
|
128
|
+
it was found with these questions.
|
|
129
|
+
- **"Caught" is generous.** A bug counts as caught if any finding points within 3 lines of
|
|
130
|
+
it, whatever the finding says. Two bugs close together can be caught by one finding.
|
|
131
|
+
- **AI results vary** between runs and model versions: report them with the date and model.
|
|
132
|
+
- **Answers are checked by their citations only.** An answer counts as correct if it cites
|
|
133
|
+
the expected code; whether every sentence is true is not checked (that would need a
|
|
134
|
+
second model as a judge).
|
|
135
|
+
|
|
136
|
+
Next steps: a second suite on an open-source project with real bug-fix commits, large enough
|
|
137
|
+
to show where the agent beats RAG; questions whose words differ from the code's (where hybrid
|
|
138
|
+
search can still rank the answer low); running each AI eval several times and reporting the
|
|
139
|
+
range; and comparing models on the same suite.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CodeScope contributors
|
|
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,214 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: codescope-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Understand a Python codebase: docs linked to the source, cited answers (RAG or an agent), change review, and MCP tools for AI apps.
|
|
5
|
+
Project-URL: Homepage, https://github.com/kushpatel2012/codescope
|
|
6
|
+
Project-URL: Source, https://github.com/kushpatel2012/codescope
|
|
7
|
+
Project-URL: Issues, https://github.com/kushpatel2012/codescope/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/kushpatel2012/codescope/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Evaluation, https://github.com/kushpatel2012/codescope/blob/main/EVALUATION.md
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agent,code-review,documentation,llm,mcp,rag,static-analysis
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: google-genai<2,>=1.20
|
|
24
|
+
Requires-Dist: httpx>=0.27
|
|
25
|
+
Requires-Dist: jinja2>=3.1
|
|
26
|
+
Requires-Dist: pydantic>=2.6
|
|
27
|
+
Requires-Dist: rich>=13.7
|
|
28
|
+
Requires-Dist: sqlite-vec>=0.1.6
|
|
29
|
+
Requires-Dist: tree-sitter-python>=0.25
|
|
30
|
+
Requires-Dist: tree-sitter>=0.25
|
|
31
|
+
Requires-Dist: typer>=0.12
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: mcp<2,>=1.10; extra == 'dev'
|
|
34
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pyyaml>=6.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
38
|
+
Requires-Dist: types-pyyaml; extra == 'dev'
|
|
39
|
+
Provides-Extra: mcp
|
|
40
|
+
Requires-Dist: mcp<2,>=1.10; extra == 'mcp'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# CodeScope
|
|
44
|
+
|
|
45
|
+
CodeScope reads a Python codebase, works out how its parts depend on each other, and writes documentation where every class, function and dependency links back to the exact source lines. With a Google Gemini API key, it also writes plain-language summaries of each file and of the whole project.
|
|
46
|
+
|
|
47
|
+
> Status: early development. Structure docs, AI summaries, questions with cited answers (RAG, or an agent that searches and reads step by step), change review, an MCP server for AI apps and a GitHub Action work today, with measured accuracy in [EVALUATION.md](https://github.com/kushpatel2012/codescope/blob/main/EVALUATION.md). A web UI is planned.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install codescope-ai # or "codescope-ai[mcp]" to also use `codescope mcp`
|
|
53
|
+
cd your-project
|
|
54
|
+
codescope init # writes .codescope.toml, ignores .codescope/
|
|
55
|
+
export GEMINI_API_KEY=... # free key: https://aistudio.google.com/apikey
|
|
56
|
+
codescope scan # indexes the code, writes AI summaries and docs/codescope/
|
|
57
|
+
codescope update # after code changes: only changed files are redone
|
|
58
|
+
codescope ask "How is an order placed?" # answer with citations to the source lines
|
|
59
|
+
codescope ask --agent "How is an order placed?" # the AI searches and reads step by step
|
|
60
|
+
codescope review --base main # what your branch changes, what it affects, tests to run
|
|
61
|
+
codescope inspect place_order
|
|
62
|
+
codescope mcp # serve these tools to Claude Code, Cursor or VS Code (MCP)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Without a key, or with `--no-llm`, CodeScope makes no AI requests and writes structure docs (summaries saved by earlier runs are kept).
|
|
66
|
+
|
|
67
|
+
## What `scan` produces
|
|
68
|
+
|
|
69
|
+
| Output | Contents |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `docs/codescope/README.md` | Overview: size, components, entry points, third-party packages, most-used modules |
|
|
72
|
+
| `docs/codescope/architecture.md` | Mermaid diagram of component dependencies, plus circular dependencies |
|
|
73
|
+
| `docs/codescope/modules/<module>.md` | Classes, methods, functions, signatures, what each calls and what calls it |
|
|
74
|
+
| `.codescope/index.db` | Local SQLite knowledge base (not committed) |
|
|
75
|
+
|
|
76
|
+
Rescans are incremental: each file's parse result and AI summary is cached by content hash, so only changed files are parsed and summarized again.
|
|
77
|
+
|
|
78
|
+
## AI summaries
|
|
79
|
+
|
|
80
|
+
Summaries are built bottom-up, because a whole codebase does not fit in one prompt:
|
|
81
|
+
|
|
82
|
+
1. **Files**: each file's code goes to a fast model (small files share one request), which returns its purpose, how it works, and one line per public class and function.
|
|
83
|
+
2. **Components**: groups of files are summarized from their file summaries.
|
|
84
|
+
3. **Project**: a stronger model writes the overview from the component summaries plus facts from static analysis.
|
|
85
|
+
|
|
86
|
+
Safeguards:
|
|
87
|
+
|
|
88
|
+
- **Secrets are removed before sending**: secret files are never read, and values like `SECRET_KEY = "..."`, passwords, API keys and private keys inside code are replaced with `<redacted>`.
|
|
89
|
+
- **Test files are not sent.**
|
|
90
|
+
- **Answers are checked**: every answer must match a JSON schema, and notes about functions that do not exist in the file are rejected.
|
|
91
|
+
- **AI text is labelled** *AI* in the docs. Names, counts and links always come from static analysis.
|
|
92
|
+
- **Free-tier friendly**: a request-per-minute limit, a per-run request budget, retries with backoff, and resumable runs. If the daily quota runs out, run again later: finished summaries are kept.
|
|
93
|
+
|
|
94
|
+
> **Privacy:** code sent to a free-tier API leaves your machine, and the provider may use it to improve its products. Use the free tier on public or personal code only.
|
|
95
|
+
|
|
96
|
+
Settings live under `[llm]` in `.codescope.toml` (models, requests per minute, request budget).
|
|
97
|
+
|
|
98
|
+
## Asking questions: `codescope ask`
|
|
99
|
+
|
|
100
|
+
Retrieval-augmented generation (RAG) over the project:
|
|
101
|
+
|
|
102
|
+
1. **Chunks**: code is split along its structure (one chunk per function, class or method, plus module-level code), and Markdown docs at headings. Test files are left out. Secrets are removed before anything is stored.
|
|
103
|
+
2. **Hybrid search**: keyword search (SQLite FTS5 with BM25, names weighted higher, `MovieBookingView` also findable as "movie booking view") plus meaning search (Gemini embeddings in [sqlite-vec](https://github.com/asg017/sqlite-vec)), merged with reciprocal rank fusion.
|
|
104
|
+
3. **Graph expansion**: code that the best matches call or are used by is added, from the dependency graph.
|
|
105
|
+
4. **Answer**: the model answers only from these numbered sources and cites them as `[S1]`. Citations to sources it was not given are removed; an answer without a valid citation is reported as "not found".
|
|
106
|
+
|
|
107
|
+
Embeddings are cached by content, so only new or changed chunks are embedded. Without an API key, `ask` lists the most relevant code instead of answering.
|
|
108
|
+
|
|
109
|
+
### Agent mode: `codescope ask --agent`
|
|
110
|
+
|
|
111
|
+
Instead of one search, the model gets two tools, `search_code` (the hybrid search above, returning code) and `read_code` (one class, function or method by name), and decides what to look at next. It can follow a trail through several files: read `return_book`, see that it calls `should_block`, read that too.
|
|
112
|
+
|
|
113
|
+
- Our code runs every tool; the model can only ask for the tools it is offered.
|
|
114
|
+
- Each piece of code a tool returns is numbered, and the answer's citations are checked exactly as above.
|
|
115
|
+
- At most 8 steps. At the limit the model gets one last turn without tools, so the work is not lost.
|
|
116
|
+
- Every step is one request, with the same budget, rate limit and retries. The output shows each step and the cost.
|
|
117
|
+
|
|
118
|
+
It costs more requests than plain `ask` (on a small project, about 7 instead of 2) and pays off when the answer is spread over code that one search does not rank highly.
|
|
119
|
+
|
|
120
|
+
## Tools for other AI apps: `codescope mcp`
|
|
121
|
+
|
|
122
|
+
`codescope mcp` runs CodeScope as an [MCP](https://modelcontextprotocol.io) server, so AI apps such as Claude Code, Cursor and VS Code can use its index and dependency graph. The app starts it and talks to it over stdin/stdout; the app's own AI decides when to call a tool.
|
|
123
|
+
|
|
124
|
+
| Tool | What it answers |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `find_callers` | What calls, imports, inherits from or uses this function, class or module: what may break if you change it |
|
|
127
|
+
| `find_dependencies` | What this calls, imports or uses inside the project |
|
|
128
|
+
| `search_code` | Code matching words or a meaning, with its source |
|
|
129
|
+
| `read_code` | The source of one class, function, method or module, by name |
|
|
130
|
+
|
|
131
|
+
Every link comes with its file and line and a confidence (certain, likely or possible). The tools are the same ones `ask --agent` uses. They need no API key; with one, `search_code` also searches by meaning. The index is refreshed when the server starts and again when it is more than 30 seconds old, so edits made during a session are seen. Secrets are removed from any code it returns.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
pip install "codescope-ai[mcp]"
|
|
135
|
+
claude mcp add codescope -- codescope mcp -p /path/to/your/project # Claude Code
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Then ask Claude Code something like "What would break if I changed `calculate_fine`?". `claude mcp list` shows the server's status and `claude mcp remove codescope` removes it. Other MCP apps take the same command (`codescope mcp -p <project>`) in their MCP settings.
|
|
139
|
+
|
|
140
|
+
## Reviewing a change: `codescope review`
|
|
141
|
+
|
|
142
|
+
Compares the working tree (commits plus uncommitted and untracked files) with where your branch left `--base` (default `main`), and writes a report to `.codescope/reviews/`.
|
|
143
|
+
|
|
144
|
+
Without AI, from the diff and the dependency graph:
|
|
145
|
+
- **Changed code**: functions and classes added, modified or removed, and changed signatures.
|
|
146
|
+
- **Impact**: code that calls, references or inherits from what changed, and code still using a removed name.
|
|
147
|
+
- **Tests to run**: test functions that use the changed code, as `pytest` node ids.
|
|
148
|
+
- **Docs to refresh**: generated pages that are now out of date.
|
|
149
|
+
|
|
150
|
+
With AI: a summary and findings (bugs, breaking changes, security, missing tests). The model sees the diff and the exact lines that use the changed code. Every finding must point at a changed line or one of those call sites; anything else is rejected. Secret files are left out and secret values redacted.
|
|
151
|
+
|
|
152
|
+
## How dependencies are found
|
|
153
|
+
|
|
154
|
+
1. **Parse** each file with [tree-sitter](https://tree-sitter.github.io/) to extract classes, functions, imports and calls, with exact line numbers.
|
|
155
|
+
2. **Resolve** names across files: imports (including relative imports and re-exports from `__init__.py`), calls, `self.method()` lookups through base classes.
|
|
156
|
+
3. **Label** every dependency with a confidence level:
|
|
157
|
+
|
|
158
|
+
| Confidence | Meaning | Example |
|
|
159
|
+
| --- | --- | --- |
|
|
160
|
+
| certain | The target is named explicitly | `from .models import Order` then `Order()`, `model = Order` in a class, or `Order` passed to a call: `get_object_or_404(Order, id=1)`, `@admin.register(Order)` |
|
|
161
|
+
| likely | Found through `self`/`cls` or a base class | `self.save()` defined on a parent class |
|
|
162
|
+
| likely | A call that leaves the project still depends on our class | `Order.objects.filter()` (Django) links to `Order` |
|
|
163
|
+
| possible | Guessed from a method name that only one class defines | `order.total()` where the type of `order` is unknown |
|
|
164
|
+
|
|
165
|
+
Known blind spots: dynamic imports, `getattr` with computed names, monkey-patching and other runtime tricks; attribute access on objects of unknown type (`booking.movie_show`); and anything outside Python files, such as templates (`{{ show.price }}`).
|
|
166
|
+
|
|
167
|
+
## GitHub Action
|
|
168
|
+
|
|
169
|
+
Review every pull request and keep the docs current. Add `.github/workflows/codescope.yml`:
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
name: CodeScope
|
|
173
|
+
|
|
174
|
+
on:
|
|
175
|
+
pull_request: # review: one comment per pull request, updated on each push
|
|
176
|
+
push:
|
|
177
|
+
branches: [main] # docs: refresh docs/codescope/ and open a pull request
|
|
178
|
+
|
|
179
|
+
permissions:
|
|
180
|
+
contents: write
|
|
181
|
+
pull-requests: write
|
|
182
|
+
|
|
183
|
+
jobs:
|
|
184
|
+
codescope:
|
|
185
|
+
runs-on: ubuntu-latest
|
|
186
|
+
steps:
|
|
187
|
+
- uses: actions/checkout@v4
|
|
188
|
+
with:
|
|
189
|
+
fetch-depth: 0 # the review compares with the target branch's history
|
|
190
|
+
- uses: kushpatel2012/codescope@v0.1.0
|
|
191
|
+
with:
|
|
192
|
+
gemini-api-key: ${{ secrets.GEMINI_API_KEY }} # optional
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
- Without `gemini-api-key`, the review still reports changed code, affected code, tests to run and docs to refresh.
|
|
196
|
+
- Pull requests from forks get no secrets and a read-only token: the review runs without AI and is shown in the job summary instead of a comment.
|
|
197
|
+
- The review never blocks a merge; it is advice.
|
|
198
|
+
- Inputs: `mode` (`review`, `docs` or `auto`), `base`, `max-calls`, `python-version`, `package`, `docs-branch`. See [action.yml](https://github.com/kushpatel2012/codescope/blob/main/action.yml).
|
|
199
|
+
|
|
200
|
+
## Evaluation
|
|
201
|
+
|
|
202
|
+
`codescope eval evals/library` measures retrieval, answers and reviews against a suite with known answers and planted bugs. Results and limits: [EVALUATION.md](https://github.com/kushpatel2012/codescope/blob/main/EVALUATION.md).
|
|
203
|
+
|
|
204
|
+
## Development
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
208
|
+
.venv/bin/pytest
|
|
209
|
+
.venv/bin/ruff check . && .venv/bin/mypy
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# CodeScope
|
|
2
|
+
|
|
3
|
+
CodeScope reads a Python codebase, works out how its parts depend on each other, and writes documentation where every class, function and dependency links back to the exact source lines. With a Google Gemini API key, it also writes plain-language summaries of each file and of the whole project.
|
|
4
|
+
|
|
5
|
+
> Status: early development. Structure docs, AI summaries, questions with cited answers (RAG, or an agent that searches and reads step by step), change review, an MCP server for AI apps and a GitHub Action work today, with measured accuracy in [EVALUATION.md](https://github.com/kushpatel2012/codescope/blob/main/EVALUATION.md). A web UI is planned.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install codescope-ai # or "codescope-ai[mcp]" to also use `codescope mcp`
|
|
11
|
+
cd your-project
|
|
12
|
+
codescope init # writes .codescope.toml, ignores .codescope/
|
|
13
|
+
export GEMINI_API_KEY=... # free key: https://aistudio.google.com/apikey
|
|
14
|
+
codescope scan # indexes the code, writes AI summaries and docs/codescope/
|
|
15
|
+
codescope update # after code changes: only changed files are redone
|
|
16
|
+
codescope ask "How is an order placed?" # answer with citations to the source lines
|
|
17
|
+
codescope ask --agent "How is an order placed?" # the AI searches and reads step by step
|
|
18
|
+
codescope review --base main # what your branch changes, what it affects, tests to run
|
|
19
|
+
codescope inspect place_order
|
|
20
|
+
codescope mcp # serve these tools to Claude Code, Cursor or VS Code (MCP)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Without a key, or with `--no-llm`, CodeScope makes no AI requests and writes structure docs (summaries saved by earlier runs are kept).
|
|
24
|
+
|
|
25
|
+
## What `scan` produces
|
|
26
|
+
|
|
27
|
+
| Output | Contents |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `docs/codescope/README.md` | Overview: size, components, entry points, third-party packages, most-used modules |
|
|
30
|
+
| `docs/codescope/architecture.md` | Mermaid diagram of component dependencies, plus circular dependencies |
|
|
31
|
+
| `docs/codescope/modules/<module>.md` | Classes, methods, functions, signatures, what each calls and what calls it |
|
|
32
|
+
| `.codescope/index.db` | Local SQLite knowledge base (not committed) |
|
|
33
|
+
|
|
34
|
+
Rescans are incremental: each file's parse result and AI summary is cached by content hash, so only changed files are parsed and summarized again.
|
|
35
|
+
|
|
36
|
+
## AI summaries
|
|
37
|
+
|
|
38
|
+
Summaries are built bottom-up, because a whole codebase does not fit in one prompt:
|
|
39
|
+
|
|
40
|
+
1. **Files**: each file's code goes to a fast model (small files share one request), which returns its purpose, how it works, and one line per public class and function.
|
|
41
|
+
2. **Components**: groups of files are summarized from their file summaries.
|
|
42
|
+
3. **Project**: a stronger model writes the overview from the component summaries plus facts from static analysis.
|
|
43
|
+
|
|
44
|
+
Safeguards:
|
|
45
|
+
|
|
46
|
+
- **Secrets are removed before sending**: secret files are never read, and values like `SECRET_KEY = "..."`, passwords, API keys and private keys inside code are replaced with `<redacted>`.
|
|
47
|
+
- **Test files are not sent.**
|
|
48
|
+
- **Answers are checked**: every answer must match a JSON schema, and notes about functions that do not exist in the file are rejected.
|
|
49
|
+
- **AI text is labelled** *AI* in the docs. Names, counts and links always come from static analysis.
|
|
50
|
+
- **Free-tier friendly**: a request-per-minute limit, a per-run request budget, retries with backoff, and resumable runs. If the daily quota runs out, run again later: finished summaries are kept.
|
|
51
|
+
|
|
52
|
+
> **Privacy:** code sent to a free-tier API leaves your machine, and the provider may use it to improve its products. Use the free tier on public or personal code only.
|
|
53
|
+
|
|
54
|
+
Settings live under `[llm]` in `.codescope.toml` (models, requests per minute, request budget).
|
|
55
|
+
|
|
56
|
+
## Asking questions: `codescope ask`
|
|
57
|
+
|
|
58
|
+
Retrieval-augmented generation (RAG) over the project:
|
|
59
|
+
|
|
60
|
+
1. **Chunks**: code is split along its structure (one chunk per function, class or method, plus module-level code), and Markdown docs at headings. Test files are left out. Secrets are removed before anything is stored.
|
|
61
|
+
2. **Hybrid search**: keyword search (SQLite FTS5 with BM25, names weighted higher, `MovieBookingView` also findable as "movie booking view") plus meaning search (Gemini embeddings in [sqlite-vec](https://github.com/asg017/sqlite-vec)), merged with reciprocal rank fusion.
|
|
62
|
+
3. **Graph expansion**: code that the best matches call or are used by is added, from the dependency graph.
|
|
63
|
+
4. **Answer**: the model answers only from these numbered sources and cites them as `[S1]`. Citations to sources it was not given are removed; an answer without a valid citation is reported as "not found".
|
|
64
|
+
|
|
65
|
+
Embeddings are cached by content, so only new or changed chunks are embedded. Without an API key, `ask` lists the most relevant code instead of answering.
|
|
66
|
+
|
|
67
|
+
### Agent mode: `codescope ask --agent`
|
|
68
|
+
|
|
69
|
+
Instead of one search, the model gets two tools, `search_code` (the hybrid search above, returning code) and `read_code` (one class, function or method by name), and decides what to look at next. It can follow a trail through several files: read `return_book`, see that it calls `should_block`, read that too.
|
|
70
|
+
|
|
71
|
+
- Our code runs every tool; the model can only ask for the tools it is offered.
|
|
72
|
+
- Each piece of code a tool returns is numbered, and the answer's citations are checked exactly as above.
|
|
73
|
+
- At most 8 steps. At the limit the model gets one last turn without tools, so the work is not lost.
|
|
74
|
+
- Every step is one request, with the same budget, rate limit and retries. The output shows each step and the cost.
|
|
75
|
+
|
|
76
|
+
It costs more requests than plain `ask` (on a small project, about 7 instead of 2) and pays off when the answer is spread over code that one search does not rank highly.
|
|
77
|
+
|
|
78
|
+
## Tools for other AI apps: `codescope mcp`
|
|
79
|
+
|
|
80
|
+
`codescope mcp` runs CodeScope as an [MCP](https://modelcontextprotocol.io) server, so AI apps such as Claude Code, Cursor and VS Code can use its index and dependency graph. The app starts it and talks to it over stdin/stdout; the app's own AI decides when to call a tool.
|
|
81
|
+
|
|
82
|
+
| Tool | What it answers |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `find_callers` | What calls, imports, inherits from or uses this function, class or module: what may break if you change it |
|
|
85
|
+
| `find_dependencies` | What this calls, imports or uses inside the project |
|
|
86
|
+
| `search_code` | Code matching words or a meaning, with its source |
|
|
87
|
+
| `read_code` | The source of one class, function, method or module, by name |
|
|
88
|
+
|
|
89
|
+
Every link comes with its file and line and a confidence (certain, likely or possible). The tools are the same ones `ask --agent` uses. They need no API key; with one, `search_code` also searches by meaning. The index is refreshed when the server starts and again when it is more than 30 seconds old, so edits made during a session are seen. Secrets are removed from any code it returns.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install "codescope-ai[mcp]"
|
|
93
|
+
claude mcp add codescope -- codescope mcp -p /path/to/your/project # Claude Code
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Then ask Claude Code something like "What would break if I changed `calculate_fine`?". `claude mcp list` shows the server's status and `claude mcp remove codescope` removes it. Other MCP apps take the same command (`codescope mcp -p <project>`) in their MCP settings.
|
|
97
|
+
|
|
98
|
+
## Reviewing a change: `codescope review`
|
|
99
|
+
|
|
100
|
+
Compares the working tree (commits plus uncommitted and untracked files) with where your branch left `--base` (default `main`), and writes a report to `.codescope/reviews/`.
|
|
101
|
+
|
|
102
|
+
Without AI, from the diff and the dependency graph:
|
|
103
|
+
- **Changed code**: functions and classes added, modified or removed, and changed signatures.
|
|
104
|
+
- **Impact**: code that calls, references or inherits from what changed, and code still using a removed name.
|
|
105
|
+
- **Tests to run**: test functions that use the changed code, as `pytest` node ids.
|
|
106
|
+
- **Docs to refresh**: generated pages that are now out of date.
|
|
107
|
+
|
|
108
|
+
With AI: a summary and findings (bugs, breaking changes, security, missing tests). The model sees the diff and the exact lines that use the changed code. Every finding must point at a changed line or one of those call sites; anything else is rejected. Secret files are left out and secret values redacted.
|
|
109
|
+
|
|
110
|
+
## How dependencies are found
|
|
111
|
+
|
|
112
|
+
1. **Parse** each file with [tree-sitter](https://tree-sitter.github.io/) to extract classes, functions, imports and calls, with exact line numbers.
|
|
113
|
+
2. **Resolve** names across files: imports (including relative imports and re-exports from `__init__.py`), calls, `self.method()` lookups through base classes.
|
|
114
|
+
3. **Label** every dependency with a confidence level:
|
|
115
|
+
|
|
116
|
+
| Confidence | Meaning | Example |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| certain | The target is named explicitly | `from .models import Order` then `Order()`, `model = Order` in a class, or `Order` passed to a call: `get_object_or_404(Order, id=1)`, `@admin.register(Order)` |
|
|
119
|
+
| likely | Found through `self`/`cls` or a base class | `self.save()` defined on a parent class |
|
|
120
|
+
| likely | A call that leaves the project still depends on our class | `Order.objects.filter()` (Django) links to `Order` |
|
|
121
|
+
| possible | Guessed from a method name that only one class defines | `order.total()` where the type of `order` is unknown |
|
|
122
|
+
|
|
123
|
+
Known blind spots: dynamic imports, `getattr` with computed names, monkey-patching and other runtime tricks; attribute access on objects of unknown type (`booking.movie_show`); and anything outside Python files, such as templates (`{{ show.price }}`).
|
|
124
|
+
|
|
125
|
+
## GitHub Action
|
|
126
|
+
|
|
127
|
+
Review every pull request and keep the docs current. Add `.github/workflows/codescope.yml`:
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
name: CodeScope
|
|
131
|
+
|
|
132
|
+
on:
|
|
133
|
+
pull_request: # review: one comment per pull request, updated on each push
|
|
134
|
+
push:
|
|
135
|
+
branches: [main] # docs: refresh docs/codescope/ and open a pull request
|
|
136
|
+
|
|
137
|
+
permissions:
|
|
138
|
+
contents: write
|
|
139
|
+
pull-requests: write
|
|
140
|
+
|
|
141
|
+
jobs:
|
|
142
|
+
codescope:
|
|
143
|
+
runs-on: ubuntu-latest
|
|
144
|
+
steps:
|
|
145
|
+
- uses: actions/checkout@v4
|
|
146
|
+
with:
|
|
147
|
+
fetch-depth: 0 # the review compares with the target branch's history
|
|
148
|
+
- uses: kushpatel2012/codescope@v0.1.0
|
|
149
|
+
with:
|
|
150
|
+
gemini-api-key: ${{ secrets.GEMINI_API_KEY }} # optional
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
- Without `gemini-api-key`, the review still reports changed code, affected code, tests to run and docs to refresh.
|
|
154
|
+
- Pull requests from forks get no secrets and a read-only token: the review runs without AI and is shown in the job summary instead of a comment.
|
|
155
|
+
- The review never blocks a merge; it is advice.
|
|
156
|
+
- Inputs: `mode` (`review`, `docs` or `auto`), `base`, `max-calls`, `python-version`, `package`, `docs-branch`. See [action.yml](https://github.com/kushpatel2012/codescope/blob/main/action.yml).
|
|
157
|
+
|
|
158
|
+
## Evaluation
|
|
159
|
+
|
|
160
|
+
`codescope eval evals/library` measures retrieval, answers and reviews against a suite with known answers and planted bugs. Results and limits: [EVALUATION.md](https://github.com/kushpatel2012/codescope/blob/main/EVALUATION.md).
|
|
161
|
+
|
|
162
|
+
## Development
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
166
|
+
.venv/bin/pytest
|
|
167
|
+
.venv/bin/ruff check . && .venv/bin/mypy
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Models used by `codescope eval evals/library`. Fixed names (not "-latest") so results
|
|
2
|
+
# from different days are comparable; report the model with every result.
|
|
3
|
+
#
|
|
4
|
+
# Free-tier limits on this key (2026-10-31): Flash Lite 15 requests/minute and 500/day;
|
|
5
|
+
# the Flash models only 5/minute and 20/day, too few for one full eval (31 requests).
|
|
6
|
+
[llm]
|
|
7
|
+
fast_model = "gemini-3.5-flash-lite"
|
|
8
|
+
strong_model = "gemini-3.5-flash-lite"
|
|
9
|
+
requests_per_minute = 10
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Library
|
|
2
|
+
|
|
3
|
+
A small lending library: a catalog of books, members who borrow them, loans with due dates,
|
|
4
|
+
and fines for late returns.
|
|
5
|
+
|
|
6
|
+
## Borrowing rules
|
|
7
|
+
|
|
8
|
+
Members can hold a limited number of loans at once. A loan lasts 21 days and can be renewed
|
|
9
|
+
twice. Books returned late are charged a daily fine, up to a maximum.
|
|
10
|
+
|
|
11
|
+
## Notifications
|
|
12
|
+
|
|
13
|
+
Members get a reminder before a loan is due and a notice once it is overdue.
|