projectbrain-mcp 0.2.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.
Files changed (41) hide show
  1. projectbrain_mcp-0.2.0/PKG-INFO +106 -0
  2. projectbrain_mcp-0.2.0/README.md +83 -0
  3. projectbrain_mcp-0.2.0/pyproject.toml +39 -0
  4. projectbrain_mcp-0.2.0/setup.cfg +4 -0
  5. projectbrain_mcp-0.2.0/src/projectbrain/__init__.py +3 -0
  6. projectbrain_mcp-0.2.0/src/projectbrain/brain.py +2850 -0
  7. projectbrain_mcp-0.2.0/src/projectbrain/classify.py +185 -0
  8. projectbrain_mcp-0.2.0/src/projectbrain/cli.py +392 -0
  9. projectbrain_mcp-0.2.0/src/projectbrain/frameworks.py +54 -0
  10. projectbrain_mcp-0.2.0/src/projectbrain/graph.py +466 -0
  11. projectbrain_mcp-0.2.0/src/projectbrain/intent.py +179 -0
  12. projectbrain_mcp-0.2.0/src/projectbrain/ledger.py +162 -0
  13. projectbrain_mcp-0.2.0/src/projectbrain/memory.py +113 -0
  14. projectbrain_mcp-0.2.0/src/projectbrain/parsers.py +997 -0
  15. projectbrain_mcp-0.2.0/src/projectbrain/patcher.py +505 -0
  16. projectbrain_mcp-0.2.0/src/projectbrain/resolve.py +202 -0
  17. projectbrain_mcp-0.2.0/src/projectbrain/server.py +356 -0
  18. projectbrain_mcp-0.2.0/src/projectbrain/session.py +359 -0
  19. projectbrain_mcp-0.2.0/src/projectbrain/slicer.py +345 -0
  20. projectbrain_mcp-0.2.0/src/projectbrain/versions.py +8 -0
  21. projectbrain_mcp-0.2.0/src/projectbrain_mcp.egg-info/PKG-INFO +106 -0
  22. projectbrain_mcp-0.2.0/src/projectbrain_mcp.egg-info/SOURCES.txt +39 -0
  23. projectbrain_mcp-0.2.0/src/projectbrain_mcp.egg-info/dependency_links.txt +1 -0
  24. projectbrain_mcp-0.2.0/src/projectbrain_mcp.egg-info/entry_points.txt +3 -0
  25. projectbrain_mcp-0.2.0/src/projectbrain_mcp.egg-info/requires.txt +10 -0
  26. projectbrain_mcp-0.2.0/src/projectbrain_mcp.egg-info/top_level.txt +1 -0
  27. projectbrain_mcp-0.2.0/tests/test_brain.py +167 -0
  28. projectbrain_mcp-0.2.0/tests/test_classify.py +61 -0
  29. projectbrain_mcp-0.2.0/tests/test_cli.py +81 -0
  30. projectbrain_mcp-0.2.0/tests/test_eval_thresholds.py +94 -0
  31. projectbrain_mcp-0.2.0/tests/test_flow.py +78 -0
  32. projectbrain_mcp-0.2.0/tests/test_frameworks.py +66 -0
  33. projectbrain_mcp-0.2.0/tests/test_graph.py +267 -0
  34. projectbrain_mcp-0.2.0/tests/test_incremental.py +132 -0
  35. projectbrain_mcp-0.2.0/tests/test_intent.py +64 -0
  36. projectbrain_mcp-0.2.0/tests/test_parsers.py +339 -0
  37. projectbrain_mcp-0.2.0/tests/test_patcher.py +133 -0
  38. projectbrain_mcp-0.2.0/tests/test_resolve.py +96 -0
  39. projectbrain_mcp-0.2.0/tests/test_session.py +117 -0
  40. projectbrain_mcp-0.2.0/tests/test_v2_brain.py +195 -0
  41. projectbrain_mcp-0.2.0/tests/test_verification.py +141 -0
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.2
2
+ Name: projectbrain-mcp
3
+ Version: 0.2.0
4
+ Summary: Surgical AST Context Compiler, Closed-World Dossier & Anchor Patch Engine for AI Coding Agents (-75% to -88% tokens)
5
+ License: MIT
6
+ Keywords: ai,agents,mcp,ast,tree-sitter,context-compression,code-graph,llm
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Software Development :: Code Generators
11
+ Classifier: Topic :: Software Development :: Compilers
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: mcp
15
+ Requires-Dist: tree-sitter>=0.23
16
+ Requires-Dist: tree-sitter-python
17
+ Requires-Dist: tree-sitter-javascript
18
+ Requires-Dist: tree-sitter-typescript
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=7; extra == "dev"
21
+ Requires-Dist: build; extra == "dev"
22
+ Requires-Dist: twine; extra == "dev"
23
+
24
+ # ProjectBrain (`projectbrain-mcp`)
25
+
26
+ **Local-first AST Context Compiler, Closed-World Dossier, and Surgical Anchor Patch Engine for AI Coding Agents.**
27
+
28
+ ProjectBrain indexes your codebase into a typed AST & call-graph (`file`, `fn`, `cls`, `route`, `mod`) in ~`90ms` and cuts coding-agent token bills by **60%–65%** while speeding up multi-file debugging by **30%–42%**:
29
+ - **Input Token Reduction (`-81.3%` to `-88.3%` code tokens, `-73.2%` to `-76.3%` billed prompt tokens):** Compiles module constants, smart-folded AST function slices, 1–3 hop bidirectional call chains with `@L<line>` caller windows, and a **Closed-World Exhaustive Repo Scan** into a single `<800`-line `.projectbrain_dossier.md` read in **1 `read_file` call**.
30
+ - **Output Token Reduction (`-63.2%` to `-77.3%` edit output tokens):** Replaces verbatim `Target` + `Replacement` repetition (`edit_file`) with a compact Anchor Patch DSL (`@file`, `@sub`, `@replace`, `@insert_after`, `@delete`) validated by Tree-sitter in `<5ms`.
31
+ - **Live ROI & Savings Ledger (`projectbrain stats`):** Tracks cumulative input/output tokens saved, file reads avoided, estimated USD saved, and developer wait-time saved in `.projectbrain_ledger.json`.
32
+
33
+ ---
34
+
35
+ ## Quick Start (60 Seconds)
36
+
37
+ ```bash
38
+ pip install projectbrain-mcp
39
+ projectbrain --path /path/to/repo init
40
+ ```
41
+
42
+ Or run as a zero-install MCP server via `uvx`:
43
+ ```json
44
+ {
45
+ "mcpServers": {
46
+ "projectbrain": {
47
+ "command": "uvx",
48
+ "args": ["projectbrain-mcp"]
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ `projectbrain init` indexes the repository, updates `.gitignore`, writes `.mcp.json` (for Claude Code, Cursor, Windsurf, Antigravity), and creates `.agents/rules/projectbrain.md` so agents automatically use `brain_dossier` and `brain_patch`.
55
+
56
+ ---
57
+
58
+ ## Verified A/B Benchmark Results (`142`-File Production Repo)
59
+
60
+ | Benchmark Scenario | Metric | Baseline Agent (No Brain) | ProjectBrain Agent | Improvement |
61
+ | :--- | :--- | :---: | :---: | :---: |
62
+ | **Scenario 1: Targeted 3-Part Engineering Analysis** | Code Output Ingested | `67,319` tok | **`12,569` tok** | **`-81.3%` (`5.35x` smaller)** |
63
+ | | Total Prompt Tokens Billed | `655,391` tok | **`155,052` tok** | **`-76.3%` (`4.23x` fewer)** |
64
+ | | File Reads (`read_file`) | `16` | **`2`** | **`-87.5%`** |
65
+ | | Net API Cost | `$0.6723` | **`$0.2590`** | **`-61.5%` (`2.60x` cheaper)** |
66
+ | **Scenario 2: Unseen Open-Ended Bug Report (Zero Identifiers)** | Code Output Ingested | `351,658` tok (`1.40M` chars) | **`40,982` tok (`163.9k` chars)** | **`-88.3%` (`8.58x` smaller)** |
67
+ | | Total Prompt Tokens Billed | `4,561,692` tok | **`1,220,579` tok** | **`-73.2%` (`-3.34M` tokens)** |
68
+ | | File Reads (`read_file`) | `84` (`19` re-reads) | **`6` (`0` re-reads)** | **`-92.9%` (`14.0x` fewer reads)** |
69
+ | | Multi-File Patch Output Tokens | `3,359` tok (`edit_file`) | **`529` – `1,237` tok** | **`-63.2%` to `-77.3%` edit output** |
70
+ | | Net API Cost | `$3.2712` | **`$1.1557`** | **`-64.7%` (`2.83x` cheaper)** |
71
+
72
+ ---
73
+
74
+ ## CLI Reference
75
+
76
+ ```bash
77
+ # 1. One-command repo initialization (index + .gitignore + .mcp.json + agent rules)
78
+ projectbrain --path <repo> init
79
+
80
+ # 2. Compile a single-read (<800-line) Engineering Dossier (.projectbrain_dossier.md)
81
+ projectbrain --path <repo> dossier "<question_or_bug_1>" "<question_or_bug_2>"
82
+
83
+ # 3. Apply or dry-run a Surgical Anchor Patch spec (.projectbrain_patch.diff)
84
+ projectbrain --path <repo> patch --spec "@file src/App.tsx
85
+ @sub L84 \`!profileCompleted\` -> \`isHydrated && !profileCompleted\`" [--apply]
86
+
87
+ # 4. View Live ROI & Token Savings Dashboard
88
+ projectbrain --path <repo> stats --summary
89
+
90
+ # 5. Additional granular tools
91
+ projectbrain --path <repo> slice --summary <file:symbol_or_start-end>
92
+ projectbrain --path <repo> compile "<task>" --summary
93
+ projectbrain --path <repo> explore <symbol_or_route> [target_b]
94
+ projectbrain --path <repo> impact <file1> [file2 ...]
95
+ projectbrain --path <repo> remember <symbol_or_file> "<architectural_note>"
96
+ ```
97
+
98
+ ---
99
+
100
+ ## MCP Server (`projectbrain-mcp`)
101
+
102
+ Exposes native MCP tools for Claude Code, Cursor, Windsurf, and Antigravity:
103
+ - `brain_dossier(tasks, impact_files=None, repo_path=None)` — Compiles `<800`-line `.projectbrain_dossier.md` with module globals, folded AST slices, call chains, and Closed-World Exhaustive Repo Scan.
104
+ - `brain_patch(spec, apply=False, repo_path=None)` — Executes or dry-runs Anchor Patch DSL (`@file`, `@sub L<n>|*|ALL|<symbol>`, `@replace`, `@insert_after`, `@delete`) with Tree-sitter syntax verification.
105
+ - `brain_stats(repo_path=None, reset=False)` — Returns cumulative token, dollar, and time savings from `.projectbrain_ledger.json`.
106
+ - `brain_slice`, `brain_context`, `brain_explore`, `brain_check`, `brain_remember`.
@@ -0,0 +1,83 @@
1
+ # ProjectBrain (`projectbrain-mcp`)
2
+
3
+ **Local-first AST Context Compiler, Closed-World Dossier, and Surgical Anchor Patch Engine for AI Coding Agents.**
4
+
5
+ ProjectBrain indexes your codebase into a typed AST & call-graph (`file`, `fn`, `cls`, `route`, `mod`) in ~`90ms` and cuts coding-agent token bills by **60%–65%** while speeding up multi-file debugging by **30%–42%**:
6
+ - **Input Token Reduction (`-81.3%` to `-88.3%` code tokens, `-73.2%` to `-76.3%` billed prompt tokens):** Compiles module constants, smart-folded AST function slices, 1–3 hop bidirectional call chains with `@L<line>` caller windows, and a **Closed-World Exhaustive Repo Scan** into a single `<800`-line `.projectbrain_dossier.md` read in **1 `read_file` call**.
7
+ - **Output Token Reduction (`-63.2%` to `-77.3%` edit output tokens):** Replaces verbatim `Target` + `Replacement` repetition (`edit_file`) with a compact Anchor Patch DSL (`@file`, `@sub`, `@replace`, `@insert_after`, `@delete`) validated by Tree-sitter in `<5ms`.
8
+ - **Live ROI & Savings Ledger (`projectbrain stats`):** Tracks cumulative input/output tokens saved, file reads avoided, estimated USD saved, and developer wait-time saved in `.projectbrain_ledger.json`.
9
+
10
+ ---
11
+
12
+ ## Quick Start (60 Seconds)
13
+
14
+ ```bash
15
+ pip install projectbrain-mcp
16
+ projectbrain --path /path/to/repo init
17
+ ```
18
+
19
+ Or run as a zero-install MCP server via `uvx`:
20
+ ```json
21
+ {
22
+ "mcpServers": {
23
+ "projectbrain": {
24
+ "command": "uvx",
25
+ "args": ["projectbrain-mcp"]
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ `projectbrain init` indexes the repository, updates `.gitignore`, writes `.mcp.json` (for Claude Code, Cursor, Windsurf, Antigravity), and creates `.agents/rules/projectbrain.md` so agents automatically use `brain_dossier` and `brain_patch`.
32
+
33
+ ---
34
+
35
+ ## Verified A/B Benchmark Results (`142`-File Production Repo)
36
+
37
+ | Benchmark Scenario | Metric | Baseline Agent (No Brain) | ProjectBrain Agent | Improvement |
38
+ | :--- | :--- | :---: | :---: | :---: |
39
+ | **Scenario 1: Targeted 3-Part Engineering Analysis** | Code Output Ingested | `67,319` tok | **`12,569` tok** | **`-81.3%` (`5.35x` smaller)** |
40
+ | | Total Prompt Tokens Billed | `655,391` tok | **`155,052` tok** | **`-76.3%` (`4.23x` fewer)** |
41
+ | | File Reads (`read_file`) | `16` | **`2`** | **`-87.5%`** |
42
+ | | Net API Cost | `$0.6723` | **`$0.2590`** | **`-61.5%` (`2.60x` cheaper)** |
43
+ | **Scenario 2: Unseen Open-Ended Bug Report (Zero Identifiers)** | Code Output Ingested | `351,658` tok (`1.40M` chars) | **`40,982` tok (`163.9k` chars)** | **`-88.3%` (`8.58x` smaller)** |
44
+ | | Total Prompt Tokens Billed | `4,561,692` tok | **`1,220,579` tok** | **`-73.2%` (`-3.34M` tokens)** |
45
+ | | File Reads (`read_file`) | `84` (`19` re-reads) | **`6` (`0` re-reads)** | **`-92.9%` (`14.0x` fewer reads)** |
46
+ | | Multi-File Patch Output Tokens | `3,359` tok (`edit_file`) | **`529` – `1,237` tok** | **`-63.2%` to `-77.3%` edit output** |
47
+ | | Net API Cost | `$3.2712` | **`$1.1557`** | **`-64.7%` (`2.83x` cheaper)** |
48
+
49
+ ---
50
+
51
+ ## CLI Reference
52
+
53
+ ```bash
54
+ # 1. One-command repo initialization (index + .gitignore + .mcp.json + agent rules)
55
+ projectbrain --path <repo> init
56
+
57
+ # 2. Compile a single-read (<800-line) Engineering Dossier (.projectbrain_dossier.md)
58
+ projectbrain --path <repo> dossier "<question_or_bug_1>" "<question_or_bug_2>"
59
+
60
+ # 3. Apply or dry-run a Surgical Anchor Patch spec (.projectbrain_patch.diff)
61
+ projectbrain --path <repo> patch --spec "@file src/App.tsx
62
+ @sub L84 \`!profileCompleted\` -> \`isHydrated && !profileCompleted\`" [--apply]
63
+
64
+ # 4. View Live ROI & Token Savings Dashboard
65
+ projectbrain --path <repo> stats --summary
66
+
67
+ # 5. Additional granular tools
68
+ projectbrain --path <repo> slice --summary <file:symbol_or_start-end>
69
+ projectbrain --path <repo> compile "<task>" --summary
70
+ projectbrain --path <repo> explore <symbol_or_route> [target_b]
71
+ projectbrain --path <repo> impact <file1> [file2 ...]
72
+ projectbrain --path <repo> remember <symbol_or_file> "<architectural_note>"
73
+ ```
74
+
75
+ ---
76
+
77
+ ## MCP Server (`projectbrain-mcp`)
78
+
79
+ Exposes native MCP tools for Claude Code, Cursor, Windsurf, and Antigravity:
80
+ - `brain_dossier(tasks, impact_files=None, repo_path=None)` — Compiles `<800`-line `.projectbrain_dossier.md` with module globals, folded AST slices, call chains, and Closed-World Exhaustive Repo Scan.
81
+ - `brain_patch(spec, apply=False, repo_path=None)` — Executes or dry-runs Anchor Patch DSL (`@file`, `@sub L<n>|*|ALL|<symbol>`, `@replace`, `@insert_after`, `@delete`) with Tree-sitter syntax verification.
82
+ - `brain_stats(repo_path=None, reset=False)` — Returns cumulative token, dollar, and time savings from `.projectbrain_ledger.json`.
83
+ - `brain_slice`, `brain_context`, `brain_explore`, `brain_check`, `brain_remember`.
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0,<77.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "projectbrain-mcp"
7
+ version = "0.2.0"
8
+ description = "Surgical AST Context Compiler, Closed-World Dossier & Anchor Patch Engine for AI Coding Agents (-75% to -88% tokens)"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.9"
12
+ keywords = ["ai", "agents", "mcp", "ast", "tree-sitter", "context-compression", "code-graph", "llm"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Intended Audience :: Developers",
16
+ "Programming Language :: Python :: 3",
17
+ "Topic :: Software Development :: Code Generators",
18
+ "Topic :: Software Development :: Compilers",
19
+ ]
20
+ dependencies = [
21
+ "mcp",
22
+ "tree-sitter>=0.23",
23
+ "tree-sitter-python",
24
+ "tree-sitter-javascript",
25
+ "tree-sitter-typescript",
26
+ ]
27
+
28
+ [project.optional-dependencies]
29
+ dev = ["pytest>=7", "build", "twine"]
30
+
31
+ [project.scripts]
32
+ projectbrain = "projectbrain.cli:main"
33
+ projectbrain-mcp = "projectbrain.server:main"
34
+
35
+ [tool.setuptools.packages.find]
36
+ where = ["src"]
37
+
38
+ [tool.pytest.ini_options]
39
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .brain import ProjectBrain
2
+
3
+ __all__ = ["ProjectBrain"]