archai-mcp 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.
- archai_mcp-0.1.0/LICENSE +21 -0
- archai_mcp-0.1.0/PKG-INFO +159 -0
- archai_mcp-0.1.0/README.md +116 -0
- archai_mcp-0.1.0/pyproject.toml +93 -0
- archai_mcp-0.1.0/setup.cfg +4 -0
- archai_mcp-0.1.0/src/archai/__init__.py +12 -0
- archai_mcp-0.1.0/src/archai/bootstrap/__init__.py +44 -0
- archai_mcp-0.1.0/src/archai/bootstrap/ast_parser.py +97 -0
- archai_mcp-0.1.0/src/archai/bootstrap/cache.py +191 -0
- archai_mcp-0.1.0/src/archai/bootstrap/dependency_resolver.py +281 -0
- archai_mcp-0.1.0/src/archai/bootstrap/file_discovery.py +61 -0
- archai_mcp-0.1.0/src/archai/bootstrap/graph_builder.py +159 -0
- archai_mcp-0.1.0/src/archai/cli/__init__.py +0 -0
- archai_mcp-0.1.0/src/archai/cli/app.py +113 -0
- archai_mcp-0.1.0/src/archai/cli/output.py +248 -0
- archai_mcp-0.1.0/src/archai/config/__init__.py +60 -0
- archai_mcp-0.1.0/src/archai/config/logging.py +100 -0
- archai_mcp-0.1.0/src/archai/inference/__init__.py +18 -0
- archai_mcp-0.1.0/src/archai/inference/clustering.py +141 -0
- archai_mcp-0.1.0/src/archai/inference/labeler.py +111 -0
- archai_mcp-0.1.0/src/archai/inference/llm/__init__.py +14 -0
- archai_mcp-0.1.0/src/archai/inference/llm/base.py +177 -0
- archai_mcp-0.1.0/src/archai/inference/llm/litellm_provider.py +118 -0
- archai_mcp-0.1.0/src/archai/mcp_server.py +86 -0
- archai_mcp-0.1.0/src/archai/middleware/__init__.py +10 -0
- archai_mcp-0.1.0/src/archai/middleware/pipeline.py +221 -0
- archai_mcp-0.1.0/src/archai/models.py +89 -0
- archai_mcp-0.1.0/src/archai/orchestrator/__init__.py +13 -0
- archai_mcp-0.1.0/src/archai/orchestrator/focus_resolver.py +57 -0
- archai_mcp-0.1.0/src/archai/orchestrator/orchestrator.py +456 -0
- archai_mcp-0.1.0/src/archai_mcp.egg-info/PKG-INFO +159 -0
- archai_mcp-0.1.0/src/archai_mcp.egg-info/SOURCES.txt +34 -0
- archai_mcp-0.1.0/src/archai_mcp.egg-info/dependency_links.txt +1 -0
- archai_mcp-0.1.0/src/archai_mcp.egg-info/entry_points.txt +2 -0
- archai_mcp-0.1.0/src/archai_mcp.egg-info/requires.txt +21 -0
- archai_mcp-0.1.0/src/archai_mcp.egg-info/top_level.txt +1 -0
archai_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cristian Chacha
|
|
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,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: archai-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cognitive Middleware for Architecture-Aware AI Coding Agents
|
|
5
|
+
Author-email: Cristian Chacha <cristianchachaleon@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/CristianChachaLeon/arch-ai
|
|
8
|
+
Project-URL: Repository, https://github.com/CristianChachaLeon/arch-ai
|
|
9
|
+
Project-URL: Documentation, https://github.com/CristianChachaLeon/arch-ai#readme
|
|
10
|
+
Project-URL: Issues, https://github.com/CristianChachaLeon/arch-ai/issues
|
|
11
|
+
Keywords: ai,coding-agent,architecture,middleware,mcp,opencode,cli
|
|
12
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: typer[all]>=0.9
|
|
24
|
+
Requires-Dist: rich>=13.0
|
|
25
|
+
Requires-Dist: pydantic>=2.0.0
|
|
26
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
27
|
+
Requires-Dist: python-dotenv>=0.18.0
|
|
28
|
+
Requires-Dist: tree-sitter>=0.20.0
|
|
29
|
+
Requires-Dist: networkx>=3.0.0
|
|
30
|
+
Requires-Dist: litellm>=1.0.0
|
|
31
|
+
Provides-Extra: mcp
|
|
32
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: httpx>=0.24.0; extra == "dev"
|
|
38
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# archai-mcp
|
|
45
|
+
|
|
46
|
+
[](https://pypi.org/project/archai-mcp/)
|
|
47
|
+
[](https://pypi.org/project/archai-mcp/)
|
|
48
|
+
[](https://github.com/CristianChachaLeon/arch-ai/blob/main/LICENSE)
|
|
49
|
+
|
|
50
|
+
Cognitive Middleware for Architecture-Aware AI Coding Agents.
|
|
51
|
+
|
|
52
|
+
## Overview
|
|
53
|
+
|
|
54
|
+
ArchAI is a middleware layer that governs how AI coding agents perceive and reason about software systems. It provides architecture-aware context to agents, reducing context pollution and architectural drift.
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Install from PyPI
|
|
60
|
+
pip install archai-mcp
|
|
61
|
+
|
|
62
|
+
# Or install with uv
|
|
63
|
+
uv tool install archai-mcp
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
After installation, the `archai` CLI is available globally.
|
|
67
|
+
|
|
68
|
+
For MCP integration, add `uvx archai-mcp mcp` to your `.opencode/mcp.json` (see [MCP Integration](#mcp-integration-agents)).
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Install
|
|
74
|
+
uv sync
|
|
75
|
+
|
|
76
|
+
# Process a repository
|
|
77
|
+
uv run archai start .
|
|
78
|
+
|
|
79
|
+
# Ask about the architecture
|
|
80
|
+
uv run archai ask "how does the login work"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## CLI Commands
|
|
84
|
+
|
|
85
|
+
| Command | Description |
|
|
86
|
+
|---------|-------------|
|
|
87
|
+
| `archai start [repo_path]` | Process a repository (bootstrap + inference pipeline) |
|
|
88
|
+
| `archai ask "query"` | Ask a question about the architecture |
|
|
89
|
+
| `archai mcp` | Start MCP server (stdio, for agent integration) |
|
|
90
|
+
|
|
91
|
+
### Examples
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Process current directory
|
|
95
|
+
archai start
|
|
96
|
+
|
|
97
|
+
# Process another repo
|
|
98
|
+
archai start /path/to/repo
|
|
99
|
+
|
|
100
|
+
# Ask questions
|
|
101
|
+
archai ask "how does the orchestrator work"
|
|
102
|
+
archai ask "what constraints does the auth module have"
|
|
103
|
+
|
|
104
|
+
# JSON output for scripting
|
|
105
|
+
archai ask "orchestrator" --json | jq '.focus'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Auto-Cache
|
|
109
|
+
|
|
110
|
+
`archai ask` automatically runs `archai start` if no cache exists. You never need to run `archai start` manually — but can if you want to pre-process.
|
|
111
|
+
|
|
112
|
+
## MCP Integration (Agents)
|
|
113
|
+
|
|
114
|
+
ArchAI exposes 3 MCP tools for AI agents:
|
|
115
|
+
|
|
116
|
+
| Tool | Description |
|
|
117
|
+
|------|-------------|
|
|
118
|
+
| `get_architecture_context` | Get context packet for a query |
|
|
119
|
+
| `validate_code_change` | Validate changes against constraints |
|
|
120
|
+
| `get_blast_radius` | Analyze impact of changing a file |
|
|
121
|
+
|
|
122
|
+
### Agent Configuration
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
// .opencode/mcp.json
|
|
126
|
+
{
|
|
127
|
+
"mcpServers": {
|
|
128
|
+
"archai": {
|
|
129
|
+
"command": "uvx",
|
|
130
|
+
"args": ["archai-mcp", "mcp"],
|
|
131
|
+
"description": "Architecture-aware context for AI coding agents"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Development
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Run tests
|
|
141
|
+
uv run pytest
|
|
142
|
+
|
|
143
|
+
# Run with coverage
|
|
144
|
+
uv run pytest --cov=src --cov-report=html
|
|
145
|
+
|
|
146
|
+
# Format code
|
|
147
|
+
uv run black src/
|
|
148
|
+
uv run ruff check src/
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Architecture
|
|
152
|
+
|
|
153
|
+
See `docs/002-sdd-cli-mcp-architecture.md` for the current architecture spec.
|
|
154
|
+
|
|
155
|
+
See `docs/001-sdd-mvp-architecture.md` for the original MVP spec (superseded by 002 for CLI/MCP sections).
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# archai-mcp
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/archai-mcp/)
|
|
4
|
+
[](https://pypi.org/project/archai-mcp/)
|
|
5
|
+
[](https://github.com/CristianChachaLeon/arch-ai/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
Cognitive Middleware for Architecture-Aware AI Coding Agents.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
ArchAI is a middleware layer that governs how AI coding agents perceive and reason about software systems. It provides architecture-aware context to agents, reducing context pollution and architectural drift.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Install from PyPI
|
|
17
|
+
pip install archai-mcp
|
|
18
|
+
|
|
19
|
+
# Or install with uv
|
|
20
|
+
uv tool install archai-mcp
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
After installation, the `archai` CLI is available globally.
|
|
24
|
+
|
|
25
|
+
For MCP integration, add `uvx archai-mcp mcp` to your `.opencode/mcp.json` (see [MCP Integration](#mcp-integration-agents)).
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Install
|
|
31
|
+
uv sync
|
|
32
|
+
|
|
33
|
+
# Process a repository
|
|
34
|
+
uv run archai start .
|
|
35
|
+
|
|
36
|
+
# Ask about the architecture
|
|
37
|
+
uv run archai ask "how does the login work"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## CLI Commands
|
|
41
|
+
|
|
42
|
+
| Command | Description |
|
|
43
|
+
|---------|-------------|
|
|
44
|
+
| `archai start [repo_path]` | Process a repository (bootstrap + inference pipeline) |
|
|
45
|
+
| `archai ask "query"` | Ask a question about the architecture |
|
|
46
|
+
| `archai mcp` | Start MCP server (stdio, for agent integration) |
|
|
47
|
+
|
|
48
|
+
### Examples
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Process current directory
|
|
52
|
+
archai start
|
|
53
|
+
|
|
54
|
+
# Process another repo
|
|
55
|
+
archai start /path/to/repo
|
|
56
|
+
|
|
57
|
+
# Ask questions
|
|
58
|
+
archai ask "how does the orchestrator work"
|
|
59
|
+
archai ask "what constraints does the auth module have"
|
|
60
|
+
|
|
61
|
+
# JSON output for scripting
|
|
62
|
+
archai ask "orchestrator" --json | jq '.focus'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Auto-Cache
|
|
66
|
+
|
|
67
|
+
`archai ask` automatically runs `archai start` if no cache exists. You never need to run `archai start` manually — but can if you want to pre-process.
|
|
68
|
+
|
|
69
|
+
## MCP Integration (Agents)
|
|
70
|
+
|
|
71
|
+
ArchAI exposes 3 MCP tools for AI agents:
|
|
72
|
+
|
|
73
|
+
| Tool | Description |
|
|
74
|
+
|------|-------------|
|
|
75
|
+
| `get_architecture_context` | Get context packet for a query |
|
|
76
|
+
| `validate_code_change` | Validate changes against constraints |
|
|
77
|
+
| `get_blast_radius` | Analyze impact of changing a file |
|
|
78
|
+
|
|
79
|
+
### Agent Configuration
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
// .opencode/mcp.json
|
|
83
|
+
{
|
|
84
|
+
"mcpServers": {
|
|
85
|
+
"archai": {
|
|
86
|
+
"command": "uvx",
|
|
87
|
+
"args": ["archai-mcp", "mcp"],
|
|
88
|
+
"description": "Architecture-aware context for AI coding agents"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Run tests
|
|
98
|
+
uv run pytest
|
|
99
|
+
|
|
100
|
+
# Run with coverage
|
|
101
|
+
uv run pytest --cov=src --cov-report=html
|
|
102
|
+
|
|
103
|
+
# Format code
|
|
104
|
+
uv run black src/
|
|
105
|
+
uv run ruff check src/
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Architecture
|
|
109
|
+
|
|
110
|
+
See `docs/002-sdd-cli-mcp-architecture.md` for the current architecture spec.
|
|
111
|
+
|
|
112
|
+
See `docs/001-sdd-mvp-architecture.md` for the original MVP spec (superseded by 002 for CLI/MCP sections).
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "archai-mcp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Cognitive Middleware for Architecture-Aware AI Coding Agents"
|
|
5
|
+
readme = {file = "README.md", content-type = "text/markdown"}
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
authors = [
|
|
8
|
+
{name = "Cristian Chacha", email = "cristianchachaleon@gmail.com"}
|
|
9
|
+
]
|
|
10
|
+
license = "MIT"
|
|
11
|
+
keywords = ["ai", "coding-agent", "architecture", "middleware", "mcp", "opencode", "cli"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
dependencies = [
|
|
24
|
+
"typer[all]>=0.9",
|
|
25
|
+
"rich>=13.0",
|
|
26
|
+
"pydantic>=2.0.0",
|
|
27
|
+
"pydantic-settings>=2.0.0",
|
|
28
|
+
"python-dotenv>=0.18.0",
|
|
29
|
+
"tree-sitter>=0.20.0",
|
|
30
|
+
"networkx>=3.0.0",
|
|
31
|
+
"litellm>=1.0.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/CristianChachaLeon/arch-ai"
|
|
36
|
+
Repository = "https://github.com/CristianChachaLeon/arch-ai"
|
|
37
|
+
Documentation = "https://github.com/CristianChachaLeon/arch-ai#readme"
|
|
38
|
+
Issues = "https://github.com/CristianChachaLeon/arch-ai/issues"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
mcp = [
|
|
42
|
+
"mcp>=1.0",
|
|
43
|
+
]
|
|
44
|
+
dev = [
|
|
45
|
+
"pytest>=7.0.0",
|
|
46
|
+
"pytest-asyncio>=0.21.0",
|
|
47
|
+
"pytest-cov>=4.0.0",
|
|
48
|
+
"httpx>=0.24.0",
|
|
49
|
+
"black>=23.0.0",
|
|
50
|
+
"ruff>=0.1.0",
|
|
51
|
+
"mypy>=1.0.0",
|
|
52
|
+
"pre-commit>=3.0.0",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[project.scripts]
|
|
56
|
+
archai = "archai.cli.app:app"
|
|
57
|
+
|
|
58
|
+
[build-system]
|
|
59
|
+
requires = ["setuptools>=61.0"]
|
|
60
|
+
build-backend = "setuptools.build_meta"
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
asyncio_mode = "auto"
|
|
64
|
+
testpaths = ["tests"]
|
|
65
|
+
addopts = "-v --tb=short"
|
|
66
|
+
|
|
67
|
+
[tool.coverage.run]
|
|
68
|
+
source = ["src"]
|
|
69
|
+
branch = true
|
|
70
|
+
|
|
71
|
+
[tool.coverage.report]
|
|
72
|
+
exclude_lines = [
|
|
73
|
+
"pragma: no cover",
|
|
74
|
+
"if TYPE_CHECKING:",
|
|
75
|
+
"if __name__ == .__main__.:",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[tool.black]
|
|
79
|
+
line-length = 100
|
|
80
|
+
target-version = ["py311"]
|
|
81
|
+
|
|
82
|
+
[tool.ruff]
|
|
83
|
+
line-length = 100
|
|
84
|
+
target-version = "py311"
|
|
85
|
+
|
|
86
|
+
[tool.setuptools.packages.find]
|
|
87
|
+
where = ["src"]
|
|
88
|
+
|
|
89
|
+
[tool.mypy]
|
|
90
|
+
python_version = "3.11"
|
|
91
|
+
warn_return_any = true
|
|
92
|
+
warn_unused_configs = true
|
|
93
|
+
disallow_untyped_defs = false
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""ArchAI - Cognitive Middleware for Architecture-Aware AI Coding Agents.
|
|
2
|
+
|
|
3
|
+
Main entry point for the ArchAI library.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from archai.middleware import ArchaiMiddleware
|
|
7
|
+
from archai.middleware.pipeline import PipelineResult
|
|
8
|
+
from archai.orchestrator import ArchaiOrchestrator
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
11
|
+
|
|
12
|
+
__all__ = ["ArchaiMiddleware", "PipelineResult", "ArchaiOrchestrator"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""ArchAI Bootstrap Module - File discovery and bootstrap utilities.
|
|
2
|
+
|
|
3
|
+
Pipeline:
|
|
4
|
+
1. file_discovery - find all .py files
|
|
5
|
+
2. ast_parser - parse files and extract metadata
|
|
6
|
+
3. dependency_resolver - resolve imports to filenames
|
|
7
|
+
4. graph_builder - build NetworkX graph
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from archai.bootstrap.file_discovery import discover_python_files
|
|
11
|
+
from archai.bootstrap.ast_parser import parse_python_file, get_imports, get_functions, get_classes
|
|
12
|
+
from archai.bootstrap.dependency_resolver import resolve_imports, FileNode
|
|
13
|
+
from archai.bootstrap.graph_builder import build_graph, FileGraph
|
|
14
|
+
from archai.bootstrap.cache import (
|
|
15
|
+
compute_repo_hash,
|
|
16
|
+
save_cache,
|
|
17
|
+
load_cache,
|
|
18
|
+
cache_exists,
|
|
19
|
+
invalidate_cache,
|
|
20
|
+
get_cache_path,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
# Discovery
|
|
25
|
+
"discover_python_files",
|
|
26
|
+
# Parsing
|
|
27
|
+
"parse_python_file",
|
|
28
|
+
"get_imports",
|
|
29
|
+
"get_functions",
|
|
30
|
+
"get_classes",
|
|
31
|
+
# Resolution
|
|
32
|
+
"resolve_imports",
|
|
33
|
+
# Graph
|
|
34
|
+
"build_graph",
|
|
35
|
+
"FileNode",
|
|
36
|
+
"FileGraph",
|
|
37
|
+
# Cache
|
|
38
|
+
"compute_repo_hash",
|
|
39
|
+
"save_cache",
|
|
40
|
+
"load_cache",
|
|
41
|
+
"cache_exists",
|
|
42
|
+
"invalidate_cache",
|
|
43
|
+
"get_cache_path",
|
|
44
|
+
]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""AST Parser - Parse Python files using standard library ast module.
|
|
2
|
+
|
|
3
|
+
Note: This implementation uses Python's built-in ast module for reliability.
|
|
4
|
+
Future versions can integrate tree-sitter for faster parsing and multi-language support.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import ast
|
|
8
|
+
import tokenize
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_python_file(file_path: Path) -> ast.AST:
|
|
13
|
+
"""
|
|
14
|
+
Parses a Python file and returns its AST using the standard library.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
file_path: Path to the Python file.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
An ast.AST object representing the parsed file.
|
|
21
|
+
|
|
22
|
+
Raises:
|
|
23
|
+
SyntaxError: If the file contains invalid Python syntax.
|
|
24
|
+
FileNotFoundError: If the file does not exist.
|
|
25
|
+
"""
|
|
26
|
+
with tokenize.open(file_path) as f:
|
|
27
|
+
code = f.read()
|
|
28
|
+
if not code.strip():
|
|
29
|
+
# Return an empty Module for empty files
|
|
30
|
+
return ast.Module(body=[], type_ignores=[])
|
|
31
|
+
|
|
32
|
+
return ast.parse(code, filename=str(file_path))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_imports(tree: ast.AST) -> list[str]:
|
|
36
|
+
"""
|
|
37
|
+
Extracts all import statements from an AST.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
tree: The parsed AST tree.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
List of imported module/component names.
|
|
44
|
+
"""
|
|
45
|
+
imports = []
|
|
46
|
+
|
|
47
|
+
for node in ast.walk(tree):
|
|
48
|
+
if isinstance(node, ast.Import):
|
|
49
|
+
for alias in node.names:
|
|
50
|
+
imports.append(alias.name)
|
|
51
|
+
elif isinstance(node, ast.ImportFrom):
|
|
52
|
+
rel_prefix = "." * node.level
|
|
53
|
+
for alias in node.names:
|
|
54
|
+
if node.module:
|
|
55
|
+
imports.append(f"{rel_prefix}{node.module}.{alias.name}")
|
|
56
|
+
else:
|
|
57
|
+
imports.append(f"{rel_prefix}{alias.name}")
|
|
58
|
+
|
|
59
|
+
return imports
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def get_functions(tree: ast.AST) -> list[str]:
|
|
63
|
+
"""
|
|
64
|
+
Extracts all function definitions from an AST.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
tree: The parsed AST tree.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
List of function names.
|
|
71
|
+
"""
|
|
72
|
+
functions = []
|
|
73
|
+
|
|
74
|
+
for node in ast.walk(tree):
|
|
75
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
76
|
+
functions.append(node.name)
|
|
77
|
+
|
|
78
|
+
return functions
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def get_classes(tree: ast.AST) -> list[str]:
|
|
82
|
+
"""
|
|
83
|
+
Extracts all class definitions from an AST.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
tree: The parsed AST tree.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
List of class names.
|
|
90
|
+
"""
|
|
91
|
+
classes = []
|
|
92
|
+
|
|
93
|
+
for node in ast.walk(tree):
|
|
94
|
+
if isinstance(node, ast.ClassDef):
|
|
95
|
+
classes.append(node.name)
|
|
96
|
+
|
|
97
|
+
return classes
|