context-gen-cli 1.0.0__tar.gz → 1.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.
- context_gen_cli-1.2.0/PKG-INFO +137 -0
- context_gen_cli-1.2.0/README.md +110 -0
- context_gen_cli-1.2.0/context_gen/cli.py +266 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen/generator.py +73 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen/scanner.py +23 -11
- context_gen_cli-1.2.0/context_gen_cli.egg-info/PKG-INFO +137 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/pyproject.toml +1 -1
- context_gen_cli-1.0.0/PKG-INFO +0 -53
- context_gen_cli-1.0.0/README.md +0 -26
- context_gen_cli-1.0.0/context_gen/cli.py +0 -124
- context_gen_cli-1.0.0/context_gen_cli.egg-info/PKG-INFO +0 -53
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen/__init__.py +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen/extractor.py +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen/graph.py +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen_cli.egg-info/SOURCES.txt +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen_cli.egg-info/dependency_links.txt +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen_cli.egg-info/entry_points.txt +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen_cli.egg-info/requires.txt +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen_cli.egg-info/top_level.txt +0 -0
- {context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/setup.cfg +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: context-gen-cli
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: A modern CLI tool that scans any project, builds an AST-based dependency graph, and generates structured LLM context (agent.md / agent.json).
|
|
5
|
+
Author: yakkshit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: llm,context,agent,cli,code-analysis,ast,graph,mcp
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: typer[all]>=0.12.0
|
|
21
|
+
Requires-Dist: rich>=13.7.0
|
|
22
|
+
Requires-Dist: pathspec>=0.12.1
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
25
|
+
Requires-Dist: build>=1.1.0; extra == "dev"
|
|
26
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
27
|
+
|
|
28
|
+
# ⚡ context-gen-cli (Python Edition)
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/context-gen-cli/)
|
|
31
|
+
[](https://pypi.org/project/context-gen-cli/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
> ⚡ **Fast, AST-powered Python CLI tool that scans any project, extracts architecture models, and generates structured LLM context (`agent.md`, `agent.json`, `agent.yaml`).**
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🌟 Highlights
|
|
39
|
+
|
|
40
|
+
- **100% Accurate Python Dependency Graphs**: Built using Python's native `ast` (Abstract Syntax Tree) module to resolve imports, relative packages, entry points, and utilities without regex guesswork.
|
|
41
|
+
- **⚡ All-In-One Default Mode (`-d`)**: Auto-generates triple context formats in `context/` and runs a live auto-sync watcher in the background.
|
|
42
|
+
- **`.gitignore` & Multi-Ignore Respect**: Automatically parses rules from `.gitignore`, `.npmignore`, `.dockerignore`, `.contextignore`, `.ignore`, and filters `.env*` secrets.
|
|
43
|
+
- **Triple Format Output**: Generates Markdown (`agent.md`), MCP-compatible structured JSON (`agent.json`), and clean YAML (`agent.yaml`).
|
|
44
|
+
- **🔄 Auto-Sync Watch Mode (`-w`)**: Monitors workspace changes and updates context files automatically on save.
|
|
45
|
+
- **Configuration Parity**: Seamlessly reads `.context-gen.json` if present to maintain unified project settings with the Node.js edition.
|
|
46
|
+
- **Modern CLI**: Styled with `typer` and `rich` for rich terminal output and progress reporting.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 📦 Installation
|
|
51
|
+
|
|
52
|
+
Install from PyPI using `pip` (or `pipx` / `uv`):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install context-gen-cli
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🚀 Quick Start
|
|
61
|
+
|
|
62
|
+
### 1. ⚡ All-In-One Default Mode (Recommended)
|
|
63
|
+
Generates all formats in `context/` and starts the live auto-sync watcher in background:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
context-gen -d
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. Generate All Formats (Markdown, JSON, YAML)
|
|
70
|
+
Scans the current directory and outputs `agent.md`, `agent.json`, and `agent.yaml` in `context/`:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
context-gen .
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Generate Specific Format (JSON / MD / YAML)
|
|
77
|
+
Generate only the format you need:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Generate MCP-ready JSON
|
|
81
|
+
context-gen . --format json
|
|
82
|
+
|
|
83
|
+
# Generate Markdown
|
|
84
|
+
context-gen . --format md
|
|
85
|
+
|
|
86
|
+
# Generate YAML
|
|
87
|
+
context-gen . --format yaml
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. Watch Mode
|
|
91
|
+
Keep context files fresh automatically on every file edit:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
context-gen . --watch
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 5. Custom Output Destination & Directory Depth
|
|
98
|
+
```bash
|
|
99
|
+
context-gen ./my-project -o custom/docs/context.md --max-depth 4
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 📖 CLI Reference
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
Usage: context-gen [OPTIONS] [PATH]
|
|
108
|
+
|
|
109
|
+
Arguments:
|
|
110
|
+
[PATH] Target project directory to analyze [default: .]
|
|
111
|
+
|
|
112
|
+
Options:
|
|
113
|
+
-d, --default ⚡ Zero-config default mode: generate all formats in context/ and run live auto-sync watcher
|
|
114
|
+
-f, --format [all|md|json|yaml] Output format [default: all]
|
|
115
|
+
-o, --output PATH Custom output file path (e.g. context/agent.md or custom.json)
|
|
116
|
+
-w, --watch Watch directory and auto-regenerate context on file changes
|
|
117
|
+
--max-depth INTEGER Maximum directory depth to scan (1-10) [default: 3]
|
|
118
|
+
--help Show this message and exit
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 🌐 Node.js & Live MCP Server
|
|
124
|
+
|
|
125
|
+
Looking for the live MCP server with interactive SSE streaming and public tunnels? Check out the [Node.js edition](https://www.npmjs.com/package/context-gen-cli):
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npx context-gen-cli -d
|
|
129
|
+
# or
|
|
130
|
+
npx context-gen-cli --mcp
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 📄 License
|
|
136
|
+
|
|
137
|
+
MIT © [yakkshit](https://github.com/yakkshit)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# ⚡ context-gen-cli (Python Edition)
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/context-gen-cli/)
|
|
4
|
+
[](https://pypi.org/project/context-gen-cli/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
> ⚡ **Fast, AST-powered Python CLI tool that scans any project, extracts architecture models, and generates structured LLM context (`agent.md`, `agent.json`, `agent.yaml`).**
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🌟 Highlights
|
|
12
|
+
|
|
13
|
+
- **100% Accurate Python Dependency Graphs**: Built using Python's native `ast` (Abstract Syntax Tree) module to resolve imports, relative packages, entry points, and utilities without regex guesswork.
|
|
14
|
+
- **⚡ All-In-One Default Mode (`-d`)**: Auto-generates triple context formats in `context/` and runs a live auto-sync watcher in the background.
|
|
15
|
+
- **`.gitignore` & Multi-Ignore Respect**: Automatically parses rules from `.gitignore`, `.npmignore`, `.dockerignore`, `.contextignore`, `.ignore`, and filters `.env*` secrets.
|
|
16
|
+
- **Triple Format Output**: Generates Markdown (`agent.md`), MCP-compatible structured JSON (`agent.json`), and clean YAML (`agent.yaml`).
|
|
17
|
+
- **🔄 Auto-Sync Watch Mode (`-w`)**: Monitors workspace changes and updates context files automatically on save.
|
|
18
|
+
- **Configuration Parity**: Seamlessly reads `.context-gen.json` if present to maintain unified project settings with the Node.js edition.
|
|
19
|
+
- **Modern CLI**: Styled with `typer` and `rich` for rich terminal output and progress reporting.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
Install from PyPI using `pip` (or `pipx` / `uv`):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install context-gen-cli
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🚀 Quick Start
|
|
34
|
+
|
|
35
|
+
### 1. ⚡ All-In-One Default Mode (Recommended)
|
|
36
|
+
Generates all formats in `context/` and starts the live auto-sync watcher in background:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
context-gen -d
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Generate All Formats (Markdown, JSON, YAML)
|
|
43
|
+
Scans the current directory and outputs `agent.md`, `agent.json`, and `agent.yaml` in `context/`:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
context-gen .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 3. Generate Specific Format (JSON / MD / YAML)
|
|
50
|
+
Generate only the format you need:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Generate MCP-ready JSON
|
|
54
|
+
context-gen . --format json
|
|
55
|
+
|
|
56
|
+
# Generate Markdown
|
|
57
|
+
context-gen . --format md
|
|
58
|
+
|
|
59
|
+
# Generate YAML
|
|
60
|
+
context-gen . --format yaml
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 4. Watch Mode
|
|
64
|
+
Keep context files fresh automatically on every file edit:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
context-gen . --watch
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 5. Custom Output Destination & Directory Depth
|
|
71
|
+
```bash
|
|
72
|
+
context-gen ./my-project -o custom/docs/context.md --max-depth 4
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 📖 CLI Reference
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
Usage: context-gen [OPTIONS] [PATH]
|
|
81
|
+
|
|
82
|
+
Arguments:
|
|
83
|
+
[PATH] Target project directory to analyze [default: .]
|
|
84
|
+
|
|
85
|
+
Options:
|
|
86
|
+
-d, --default ⚡ Zero-config default mode: generate all formats in context/ and run live auto-sync watcher
|
|
87
|
+
-f, --format [all|md|json|yaml] Output format [default: all]
|
|
88
|
+
-o, --output PATH Custom output file path (e.g. context/agent.md or custom.json)
|
|
89
|
+
-w, --watch Watch directory and auto-regenerate context on file changes
|
|
90
|
+
--max-depth INTEGER Maximum directory depth to scan (1-10) [default: 3]
|
|
91
|
+
--help Show this message and exit
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 🌐 Node.js & Live MCP Server
|
|
97
|
+
|
|
98
|
+
Looking for the live MCP server with interactive SSE streaming and public tunnels? Check out the [Node.js edition](https://www.npmjs.com/package/context-gen-cli):
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npx context-gen-cli -d
|
|
102
|
+
# or
|
|
103
|
+
npx context-gen-cli --mcp
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 📄 License
|
|
109
|
+
|
|
110
|
+
MIT © [yakkshit](https://github.com/yakkshit)
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""
|
|
2
|
+
context_gen.cli: Typer-based CLI entry point for context-gen-cli (Python Edition).
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import time
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import List, Optional
|
|
11
|
+
import typer
|
|
12
|
+
from rich.console import Console
|
|
13
|
+
from rich.panel import Panel
|
|
14
|
+
from rich.table import Table
|
|
15
|
+
|
|
16
|
+
from context_gen.scanner import scan_project
|
|
17
|
+
from context_gen.extractor import extract_metadata
|
|
18
|
+
from context_gen.graph import build_dependency_graph
|
|
19
|
+
from context_gen.generator import generate_agent_md, generate_agent_json, generate_agent_yaml
|
|
20
|
+
|
|
21
|
+
app = typer.Typer(
|
|
22
|
+
name="context-gen",
|
|
23
|
+
help="⚡ Generate graph-based project context (agent.md, agent.json, agent.yaml) for LLMs.",
|
|
24
|
+
add_completion=False,
|
|
25
|
+
no_args_is_help=False
|
|
26
|
+
)
|
|
27
|
+
console = Console()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class OutputFormat(str, Enum):
|
|
31
|
+
"""Supported output formats."""
|
|
32
|
+
ALL = "all"
|
|
33
|
+
MD = "md"
|
|
34
|
+
JSON = "json"
|
|
35
|
+
YAML = "yaml"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def execute_generation(
|
|
39
|
+
target_dir: Path,
|
|
40
|
+
format_choice: OutputFormat,
|
|
41
|
+
output_override: Optional[Path] = None,
|
|
42
|
+
max_depth: int = 3,
|
|
43
|
+
verbose: bool = True
|
|
44
|
+
) -> dict:
|
|
45
|
+
"""Scans and generates the requested context format files."""
|
|
46
|
+
scan_result = scan_project(str(target_dir), max_depth=max_depth)
|
|
47
|
+
files = scan_result["files"]
|
|
48
|
+
tree = scan_result["tree"]
|
|
49
|
+
|
|
50
|
+
metadata = extract_metadata(str(target_dir), files)
|
|
51
|
+
graph = build_dependency_graph(files, str(target_dir))
|
|
52
|
+
|
|
53
|
+
# Read output directory from .context-gen.json if available
|
|
54
|
+
config_file = target_dir / ".context-gen.json"
|
|
55
|
+
output_dir_name = "context"
|
|
56
|
+
if config_file.is_file():
|
|
57
|
+
try:
|
|
58
|
+
with open(config_file, "r", encoding="utf-8") as f:
|
|
59
|
+
cfg = json.load(f)
|
|
60
|
+
output_dir_name = cfg.get("outputDir", "context")
|
|
61
|
+
except Exception:
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
dest_dir = target_dir / output_dir_name
|
|
65
|
+
dest_dir.mkdir(parents=True, exist_ok=True)
|
|
66
|
+
|
|
67
|
+
generated_files: List[Path] = []
|
|
68
|
+
|
|
69
|
+
if output_override:
|
|
70
|
+
out_file = output_override.resolve()
|
|
71
|
+
out_file.parent.mkdir(parents=True, exist_ok=True)
|
|
72
|
+
if format_choice == OutputFormat.JSON:
|
|
73
|
+
json_data = generate_agent_json(metadata, graph, tree, str(target_dir))
|
|
74
|
+
out_file.write_text(json.dumps(json_data, indent=2), encoding="utf-8")
|
|
75
|
+
elif format_choice == OutputFormat.YAML:
|
|
76
|
+
yaml_text = generate_agent_yaml(metadata, graph, tree, str(target_dir))
|
|
77
|
+
out_file.write_text(yaml_text, encoding="utf-8")
|
|
78
|
+
else:
|
|
79
|
+
md_text = generate_agent_md(metadata, graph, tree)
|
|
80
|
+
out_file.write_text(md_text, encoding="utf-8")
|
|
81
|
+
generated_files.append(out_file)
|
|
82
|
+
else:
|
|
83
|
+
# Determine formats to generate
|
|
84
|
+
formats_to_build = ["md", "json", "yaml"] if format_choice == OutputFormat.ALL else [format_choice.value]
|
|
85
|
+
|
|
86
|
+
if "md" in formats_to_build:
|
|
87
|
+
md_file = dest_dir / "agent.md"
|
|
88
|
+
md_text = generate_agent_md(metadata, graph, tree)
|
|
89
|
+
md_file.write_text(md_text, encoding="utf-8")
|
|
90
|
+
generated_files.append(md_file)
|
|
91
|
+
|
|
92
|
+
if "json" in formats_to_build:
|
|
93
|
+
json_file = dest_dir / "agent.json"
|
|
94
|
+
json_data = generate_agent_json(metadata, graph, tree, str(target_dir))
|
|
95
|
+
json_file.write_text(json.dumps(json_data, indent=2), encoding="utf-8")
|
|
96
|
+
generated_files.append(json_file)
|
|
97
|
+
|
|
98
|
+
if "yaml" in formats_to_build:
|
|
99
|
+
yaml_file = dest_dir / "agent.yaml"
|
|
100
|
+
yaml_text = generate_agent_yaml(metadata, graph, tree, str(target_dir))
|
|
101
|
+
yaml_file.write_text(yaml_text, encoding="utf-8")
|
|
102
|
+
generated_files.append(yaml_file)
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
"files": files,
|
|
106
|
+
"graph": graph,
|
|
107
|
+
"metadata": metadata,
|
|
108
|
+
"generated_files": generated_files,
|
|
109
|
+
"output_dir": dest_dir
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def run_watch_loop(target_dir: Path, format_choice: OutputFormat, max_depth: int = 3) -> None:
|
|
114
|
+
"""Runs a live background file watch loop that regenerates context on changes."""
|
|
115
|
+
console.print(
|
|
116
|
+
Panel(
|
|
117
|
+
f"[bold cyan]👀 Watch Mode Active[/bold cyan]\n"
|
|
118
|
+
f"[dim]Monitoring workspace:[/dim] [green]{target_dir}[/green]\n"
|
|
119
|
+
f"[dim]Auto-updating context files on save. Press [bold]Ctrl+C[/bold] to exit.[/dim]",
|
|
120
|
+
border_style="cyan"
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
last_snapshot = {}
|
|
125
|
+
|
|
126
|
+
def get_snapshot():
|
|
127
|
+
snap = {}
|
|
128
|
+
for p in target_dir.rglob("*"):
|
|
129
|
+
if p.is_file():
|
|
130
|
+
rel = p.relative_to(target_dir).as_posix()
|
|
131
|
+
if not any(token in rel for token in ["context/", "node_modules/", ".git/", "__pycache__/", ".venv/", "agent."]):
|
|
132
|
+
try:
|
|
133
|
+
snap[rel] = p.stat().st_mtime
|
|
134
|
+
except Exception:
|
|
135
|
+
pass
|
|
136
|
+
return snap
|
|
137
|
+
|
|
138
|
+
last_snapshot = get_snapshot()
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
while True:
|
|
142
|
+
time.sleep(1.0)
|
|
143
|
+
current_snapshot = get_snapshot()
|
|
144
|
+
|
|
145
|
+
changed = False
|
|
146
|
+
for f, mtime in current_snapshot.items():
|
|
147
|
+
if f not in last_snapshot or last_snapshot[f] != mtime:
|
|
148
|
+
changed = True
|
|
149
|
+
break
|
|
150
|
+
|
|
151
|
+
if not changed and set(last_snapshot.keys()) != set(current_snapshot.keys()):
|
|
152
|
+
changed = True
|
|
153
|
+
|
|
154
|
+
if changed:
|
|
155
|
+
last_snapshot = current_snapshot
|
|
156
|
+
time_str = datetime.now().strftime("%H:%M:%S")
|
|
157
|
+
console.print(f"[dim][{time_str}][/dim] [bold green]🔄 Project changed. Regenerating context files...[/bold green]")
|
|
158
|
+
execute_generation(target_dir, format_choice, max_depth=max_depth, verbose=False)
|
|
159
|
+
console.print(f"[dim][{time_str}][/dim] [bold cyan]✓ Context files updated & synced in context/![/bold cyan]")
|
|
160
|
+
except KeyboardInterrupt:
|
|
161
|
+
console.print("\n[bold yellow]👋 Stopping watch mode...[/bold yellow]")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@app.command()
|
|
165
|
+
def main(
|
|
166
|
+
path: Path = typer.Argument(
|
|
167
|
+
default=Path("."),
|
|
168
|
+
help="Target project directory to analyze.",
|
|
169
|
+
exists=True,
|
|
170
|
+
file_okay=False,
|
|
171
|
+
dir_okay=True,
|
|
172
|
+
readable=True,
|
|
173
|
+
resolve_path=True,
|
|
174
|
+
),
|
|
175
|
+
default_mode: bool = typer.Option(
|
|
176
|
+
False,
|
|
177
|
+
"--default",
|
|
178
|
+
"-d",
|
|
179
|
+
help="⚡ Zero-config default mode: generate all formats in context/ and run live auto-sync watcher.",
|
|
180
|
+
),
|
|
181
|
+
format: OutputFormat = typer.Option(
|
|
182
|
+
OutputFormat.ALL,
|
|
183
|
+
"--format",
|
|
184
|
+
"-f",
|
|
185
|
+
help="Output format: 'all', 'md', 'json', or 'yaml'.",
|
|
186
|
+
case_sensitive=False,
|
|
187
|
+
),
|
|
188
|
+
output: Optional[Path] = typer.Option(
|
|
189
|
+
None,
|
|
190
|
+
"--output",
|
|
191
|
+
"-o",
|
|
192
|
+
help="Custom output file path (e.g. context/agent.md or custom.json).",
|
|
193
|
+
),
|
|
194
|
+
watch: bool = typer.Option(
|
|
195
|
+
False,
|
|
196
|
+
"--watch",
|
|
197
|
+
"-w",
|
|
198
|
+
help="Watch directory and auto-regenerate context on file changes.",
|
|
199
|
+
),
|
|
200
|
+
max_depth: int = typer.Option(
|
|
201
|
+
3,
|
|
202
|
+
"--max-depth",
|
|
203
|
+
help="Maximum directory depth to scan.",
|
|
204
|
+
min=1,
|
|
205
|
+
max=10,
|
|
206
|
+
),
|
|
207
|
+
) -> None:
|
|
208
|
+
"""
|
|
209
|
+
Scan a project, build an AST-powered dependency graph, and generate LLM context.
|
|
210
|
+
"""
|
|
211
|
+
target_dir = path.resolve()
|
|
212
|
+
|
|
213
|
+
# If -d / --default is supplied, generate all formats and keep watch running
|
|
214
|
+
if default_mode:
|
|
215
|
+
console.print(
|
|
216
|
+
Panel.fit(
|
|
217
|
+
f"[bold cyan]⚡ context-gen-cli (Python All-In-One Mode -d)[/bold cyan]\n"
|
|
218
|
+
f"[dim]Target:[/dim] [green]{target_dir}[/green]\n"
|
|
219
|
+
f"[dim]Mode:[/dim] [yellow]Auto-Generate All Formats + Live Background Watcher[/yellow]",
|
|
220
|
+
border_style="cyan"
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
res = execute_generation(target_dir, OutputFormat.ALL, max_depth=max_depth)
|
|
224
|
+
table = Table(show_header=False, box=None)
|
|
225
|
+
table.add_row("[bold]Scanned Files:[/bold]", f"[cyan]{len(res['files'])}[/cyan]")
|
|
226
|
+
table.add_row("[bold]AST Graph Edges:[/bold]", f"[cyan]{len(res['graph']['edges'])}[/cyan]")
|
|
227
|
+
table.add_row("[bold]Tech Stack:[/bold]", f"[green]{', '.join(res['metadata']['techStack'])}[/green]")
|
|
228
|
+
table.add_row("[bold]Generated Files:[/bold]", f"[yellow]{', '.join(f.name for f in res['generated_files'])}[/yellow]")
|
|
229
|
+
console.print(Panel(table, title="[bold green]✅ Context Generated in context/[/bold green]", border_style="green"))
|
|
230
|
+
run_watch_loop(target_dir, OutputFormat.ALL, max_depth=max_depth)
|
|
231
|
+
return
|
|
232
|
+
|
|
233
|
+
console.print(
|
|
234
|
+
Panel.fit(
|
|
235
|
+
f"[bold cyan]⚡ context-gen-cli (Python Edition)[/bold cyan]\n"
|
|
236
|
+
f"[dim]Analyzing target:[/dim] [green]{target_dir}[/green]\n"
|
|
237
|
+
f"[dim]Format:[/dim] [yellow]{format.value.upper()}[/yellow]",
|
|
238
|
+
border_style="cyan"
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
with console.status("[bold green]Scanning directory and parsing AST graph...[/bold green]"):
|
|
243
|
+
res = execute_generation(target_dir, format, output_override=output, max_depth=max_depth)
|
|
244
|
+
|
|
245
|
+
# Display completion summary
|
|
246
|
+
table = Table(show_header=False, box=None)
|
|
247
|
+
table.add_row("[bold]Scanned Files:[/bold]", f"[cyan]{len(res['files'])}[/cyan]")
|
|
248
|
+
table.add_row("[bold]AST Graph Edges:[/bold]", f"[cyan]{len(res['graph']['edges'])}[/cyan]")
|
|
249
|
+
table.add_row("[bold]Tech Stack:[/bold]", f"[green]{', '.join(res['metadata']['techStack'])}[/green]")
|
|
250
|
+
table.add_row("[bold]Output Destination:[/bold]", f"[yellow]{res['output_dir']}[/yellow]")
|
|
251
|
+
table.add_row("[bold]Generated Files:[/bold]", f"[green]{', '.join(f.name for f in res['generated_files'])}[/green]")
|
|
252
|
+
|
|
253
|
+
console.print(
|
|
254
|
+
Panel(
|
|
255
|
+
table,
|
|
256
|
+
title="[bold green]✅ Context Generated Successfully[/bold green]",
|
|
257
|
+
border_style="green"
|
|
258
|
+
)
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
if watch:
|
|
262
|
+
run_watch_loop(target_dir, format, max_depth=max_depth)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
if __name__ == "__main__":
|
|
266
|
+
app()
|
|
@@ -151,3 +151,76 @@ def generate_agent_md(
|
|
|
151
151
|
])
|
|
152
152
|
|
|
153
153
|
return "\n".join(lines)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def generate_agent_yaml(
|
|
157
|
+
metadata: Dict[str, Any],
|
|
158
|
+
graph: Dict[str, Any],
|
|
159
|
+
tree: str = "",
|
|
160
|
+
project_path: str = ""
|
|
161
|
+
) -> str:
|
|
162
|
+
"""
|
|
163
|
+
Generates clean, structured YAML representation of the project context.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
metadata (Dict[str, Any]): Project metadata from extractor.
|
|
167
|
+
graph (Dict[str, Any]): AST dependency graph.
|
|
168
|
+
tree (str): Visual directory tree.
|
|
169
|
+
project_path (str): Root project path.
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
str: Formatted YAML string.
|
|
173
|
+
"""
|
|
174
|
+
now_iso = datetime.now(timezone.utc).isoformat()
|
|
175
|
+
path_val = project_path or metadata.get("projectPath", "")
|
|
176
|
+
overview = metadata.get("overview", "").replace('"', '\\"')
|
|
177
|
+
|
|
178
|
+
lines: List[str] = [
|
|
179
|
+
"# Project Architecture & Context Model (YAML)",
|
|
180
|
+
"# Generated automatically by context-gen-cli (Python Edition)",
|
|
181
|
+
"version: \"1.0.0\"",
|
|
182
|
+
f"generated_at: \"{now_iso}\"",
|
|
183
|
+
f"project_path: \"{path_val}\"",
|
|
184
|
+
f"overview: \"{overview}\"",
|
|
185
|
+
"",
|
|
186
|
+
"tech_stack:",
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
for tech in metadata.get("techStack", ["Python"]):
|
|
190
|
+
lines.append(f" - \"{tech}\"")
|
|
191
|
+
|
|
192
|
+
lines.extend([
|
|
193
|
+
"",
|
|
194
|
+
"entry_points:",
|
|
195
|
+
])
|
|
196
|
+
for ep in graph.get("entryPoints", []):
|
|
197
|
+
lines.append(f" - \"{ep}\"")
|
|
198
|
+
|
|
199
|
+
lines.extend([
|
|
200
|
+
"",
|
|
201
|
+
"utilities:",
|
|
202
|
+
])
|
|
203
|
+
for u in graph.get("utilities", []):
|
|
204
|
+
lines.append(f" - \"{u}\"")
|
|
205
|
+
|
|
206
|
+
lines.extend([
|
|
207
|
+
"",
|
|
208
|
+
"key_files:",
|
|
209
|
+
])
|
|
210
|
+
for kf in metadata.get("keyFiles", []):
|
|
211
|
+
desc = kf['description'].replace('"', '\\"')
|
|
212
|
+
lines.append(f" - path: \"{kf['path']}\"")
|
|
213
|
+
lines.append(f" description: \"{desc}\"")
|
|
214
|
+
|
|
215
|
+
lines.extend([
|
|
216
|
+
"",
|
|
217
|
+
"dependency_edges:",
|
|
218
|
+
])
|
|
219
|
+
for edge in graph.get("edges", []):
|
|
220
|
+
lines.append(f" - from: \"{edge['from']}\"")
|
|
221
|
+
lines.append(f" to: \"{edge['to']}\"")
|
|
222
|
+
lines.append(f" type: \"{edge.get('type', 'import')}\"")
|
|
223
|
+
|
|
224
|
+
lines.append("")
|
|
225
|
+
return "\n".join(lines)
|
|
226
|
+
|
|
@@ -39,7 +39,8 @@ DEFAULT_IGNORES: List[str] = [
|
|
|
39
39
|
|
|
40
40
|
def load_gitignore(root: Path) -> pathspec.PathSpec:
|
|
41
41
|
"""
|
|
42
|
-
Loads and compiles
|
|
42
|
+
Loads and compiles ignore rules from all standard ignore files (.gitignore, .npmignore, etc.)
|
|
43
|
+
along with default security ignores.
|
|
43
44
|
|
|
44
45
|
Args:
|
|
45
46
|
root (Path): The project root directory.
|
|
@@ -49,16 +50,27 @@ def load_gitignore(root: Path) -> pathspec.PathSpec:
|
|
|
49
50
|
"""
|
|
50
51
|
patterns: List[str] = list(DEFAULT_IGNORES)
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
standard_ignore_files = [
|
|
54
|
+
".gitignore",
|
|
55
|
+
".npmignore",
|
|
56
|
+
".dockerignore",
|
|
57
|
+
".contextignore",
|
|
58
|
+
".ignore",
|
|
59
|
+
".eslintignore",
|
|
60
|
+
".prettierignore"
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
for ignore_name in standard_ignore_files:
|
|
64
|
+
ignore_path = root / ignore_name
|
|
65
|
+
if ignore_path.is_file():
|
|
66
|
+
try:
|
|
67
|
+
with open(ignore_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
68
|
+
for line in f:
|
|
69
|
+
stripped = line.strip()
|
|
70
|
+
if stripped and not stripped.startswith("#"):
|
|
71
|
+
patterns.append(stripped)
|
|
72
|
+
except Exception:
|
|
73
|
+
pass
|
|
62
74
|
|
|
63
75
|
return pathspec.PathSpec.from_lines("gitwildmatch", patterns)
|
|
64
76
|
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: context-gen-cli
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: A modern CLI tool that scans any project, builds an AST-based dependency graph, and generates structured LLM context (agent.md / agent.json).
|
|
5
|
+
Author: yakkshit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: llm,context,agent,cli,code-analysis,ast,graph,mcp
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: typer[all]>=0.12.0
|
|
21
|
+
Requires-Dist: rich>=13.7.0
|
|
22
|
+
Requires-Dist: pathspec>=0.12.1
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
25
|
+
Requires-Dist: build>=1.1.0; extra == "dev"
|
|
26
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
27
|
+
|
|
28
|
+
# ⚡ context-gen-cli (Python Edition)
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/context-gen-cli/)
|
|
31
|
+
[](https://pypi.org/project/context-gen-cli/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
> ⚡ **Fast, AST-powered Python CLI tool that scans any project, extracts architecture models, and generates structured LLM context (`agent.md`, `agent.json`, `agent.yaml`).**
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🌟 Highlights
|
|
39
|
+
|
|
40
|
+
- **100% Accurate Python Dependency Graphs**: Built using Python's native `ast` (Abstract Syntax Tree) module to resolve imports, relative packages, entry points, and utilities without regex guesswork.
|
|
41
|
+
- **⚡ All-In-One Default Mode (`-d`)**: Auto-generates triple context formats in `context/` and runs a live auto-sync watcher in the background.
|
|
42
|
+
- **`.gitignore` & Multi-Ignore Respect**: Automatically parses rules from `.gitignore`, `.npmignore`, `.dockerignore`, `.contextignore`, `.ignore`, and filters `.env*` secrets.
|
|
43
|
+
- **Triple Format Output**: Generates Markdown (`agent.md`), MCP-compatible structured JSON (`agent.json`), and clean YAML (`agent.yaml`).
|
|
44
|
+
- **🔄 Auto-Sync Watch Mode (`-w`)**: Monitors workspace changes and updates context files automatically on save.
|
|
45
|
+
- **Configuration Parity**: Seamlessly reads `.context-gen.json` if present to maintain unified project settings with the Node.js edition.
|
|
46
|
+
- **Modern CLI**: Styled with `typer` and `rich` for rich terminal output and progress reporting.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 📦 Installation
|
|
51
|
+
|
|
52
|
+
Install from PyPI using `pip` (or `pipx` / `uv`):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install context-gen-cli
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🚀 Quick Start
|
|
61
|
+
|
|
62
|
+
### 1. ⚡ All-In-One Default Mode (Recommended)
|
|
63
|
+
Generates all formats in `context/` and starts the live auto-sync watcher in background:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
context-gen -d
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. Generate All Formats (Markdown, JSON, YAML)
|
|
70
|
+
Scans the current directory and outputs `agent.md`, `agent.json`, and `agent.yaml` in `context/`:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
context-gen .
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Generate Specific Format (JSON / MD / YAML)
|
|
77
|
+
Generate only the format you need:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Generate MCP-ready JSON
|
|
81
|
+
context-gen . --format json
|
|
82
|
+
|
|
83
|
+
# Generate Markdown
|
|
84
|
+
context-gen . --format md
|
|
85
|
+
|
|
86
|
+
# Generate YAML
|
|
87
|
+
context-gen . --format yaml
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. Watch Mode
|
|
91
|
+
Keep context files fresh automatically on every file edit:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
context-gen . --watch
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 5. Custom Output Destination & Directory Depth
|
|
98
|
+
```bash
|
|
99
|
+
context-gen ./my-project -o custom/docs/context.md --max-depth 4
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 📖 CLI Reference
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
Usage: context-gen [OPTIONS] [PATH]
|
|
108
|
+
|
|
109
|
+
Arguments:
|
|
110
|
+
[PATH] Target project directory to analyze [default: .]
|
|
111
|
+
|
|
112
|
+
Options:
|
|
113
|
+
-d, --default ⚡ Zero-config default mode: generate all formats in context/ and run live auto-sync watcher
|
|
114
|
+
-f, --format [all|md|json|yaml] Output format [default: all]
|
|
115
|
+
-o, --output PATH Custom output file path (e.g. context/agent.md or custom.json)
|
|
116
|
+
-w, --watch Watch directory and auto-regenerate context on file changes
|
|
117
|
+
--max-depth INTEGER Maximum directory depth to scan (1-10) [default: 3]
|
|
118
|
+
--help Show this message and exit
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 🌐 Node.js & Live MCP Server
|
|
124
|
+
|
|
125
|
+
Looking for the live MCP server with interactive SSE streaming and public tunnels? Check out the [Node.js edition](https://www.npmjs.com/package/context-gen-cli):
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npx context-gen-cli -d
|
|
129
|
+
# or
|
|
130
|
+
npx context-gen-cli --mcp
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 📄 License
|
|
136
|
+
|
|
137
|
+
MIT © [yakkshit](https://github.com/yakkshit)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "context-gen-cli"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.2.0"
|
|
8
8
|
description = "A modern CLI tool that scans any project, builds an AST-based dependency graph, and generates structured LLM context (agent.md / agent.json)."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "yakkshit" }]
|
context_gen_cli-1.0.0/PKG-INFO
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: context-gen-cli
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: A modern CLI tool that scans any project, builds an AST-based dependency graph, and generates structured LLM context (agent.md / agent.json).
|
|
5
|
-
Author: yakkshit
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Keywords: llm,context,agent,cli,code-analysis,ast,graph,mcp
|
|
8
|
-
Classifier: Development Status :: 4 - Beta
|
|
9
|
-
Classifier: Environment :: Console
|
|
10
|
-
Classifier: Intended Audience :: Developers
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
-
Requires-Python: >=3.9
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
Requires-Dist: typer[all]>=0.12.0
|
|
21
|
-
Requires-Dist: rich>=13.7.0
|
|
22
|
-
Requires-Dist: pathspec>=0.12.1
|
|
23
|
-
Provides-Extra: dev
|
|
24
|
-
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
25
|
-
Requires-Dist: build>=1.1.0; extra == "dev"
|
|
26
|
-
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
27
|
-
|
|
28
|
-
# context-gen-cli (Python Edition)
|
|
29
|
-
|
|
30
|
-
> ⚡ Fast, AST-powered CLI tool that scans any project, extracts architecture models, and generates structured LLM context (`agent.md` & `agent.json`).
|
|
31
|
-
|
|
32
|
-
## Features
|
|
33
|
-
- **100% Accurate Python Dependency Graphs**: Built using Python's native `ast` (Abstract Syntax Tree) module.
|
|
34
|
-
- **Gitignore Respect**: Uses `pathspec` to ignore unwanted directories and secrets.
|
|
35
|
-
- **Dual Output**: Generates both human-readable Markdown (`agent.md`) and MCP-compatible structured JSON (`agent.json`).
|
|
36
|
-
- **Modern CLI**: Powered by `typer` and `rich`.
|
|
37
|
-
|
|
38
|
-
## Installation
|
|
39
|
-
```bash
|
|
40
|
-
pip install context-gen-cli
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Quick Start
|
|
44
|
-
```bash
|
|
45
|
-
# Generate agent.md in context/ directory
|
|
46
|
-
context-gen .
|
|
47
|
-
|
|
48
|
-
# Generate agent.json
|
|
49
|
-
context-gen . --format json
|
|
50
|
-
|
|
51
|
-
# Custom output path
|
|
52
|
-
context-gen ./my-project -o custom/path/context.md
|
|
53
|
-
```
|
context_gen_cli-1.0.0/README.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# context-gen-cli (Python Edition)
|
|
2
|
-
|
|
3
|
-
> ⚡ Fast, AST-powered CLI tool that scans any project, extracts architecture models, and generates structured LLM context (`agent.md` & `agent.json`).
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
- **100% Accurate Python Dependency Graphs**: Built using Python's native `ast` (Abstract Syntax Tree) module.
|
|
7
|
-
- **Gitignore Respect**: Uses `pathspec` to ignore unwanted directories and secrets.
|
|
8
|
-
- **Dual Output**: Generates both human-readable Markdown (`agent.md`) and MCP-compatible structured JSON (`agent.json`).
|
|
9
|
-
- **Modern CLI**: Powered by `typer` and `rich`.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
```bash
|
|
13
|
-
pip install context-gen-cli
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Quick Start
|
|
17
|
-
```bash
|
|
18
|
-
# Generate agent.md in context/ directory
|
|
19
|
-
context-gen .
|
|
20
|
-
|
|
21
|
-
# Generate agent.json
|
|
22
|
-
context-gen . --format json
|
|
23
|
-
|
|
24
|
-
# Custom output path
|
|
25
|
-
context-gen ./my-project -o custom/path/context.md
|
|
26
|
-
```
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
context_gen.cli: Typer-based CLI entry point for context-gen-cli.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import json
|
|
6
|
-
from enum import Enum
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
from typing import Optional
|
|
9
|
-
import typer
|
|
10
|
-
from rich.console import Console
|
|
11
|
-
from rich.panel import Panel
|
|
12
|
-
from rich.table import Table
|
|
13
|
-
|
|
14
|
-
from context_gen.scanner import scan_project
|
|
15
|
-
from context_gen.extractor import extract_metadata
|
|
16
|
-
from context_gen.graph import build_dependency_graph
|
|
17
|
-
from context_gen.generator import generate_agent_md, generate_agent_json
|
|
18
|
-
|
|
19
|
-
app = typer.Typer(
|
|
20
|
-
name="context-gen",
|
|
21
|
-
help="⚡ Generate graph-based project context (agent.md / agent.json) for LLMs.",
|
|
22
|
-
add_completion=False,
|
|
23
|
-
no_args_is_help=False
|
|
24
|
-
)
|
|
25
|
-
console = Console()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class OutputFormat(str, Enum):
|
|
29
|
-
"""Supported output formats."""
|
|
30
|
-
MD = "md"
|
|
31
|
-
JSON = "json"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@app.command()
|
|
35
|
-
def main(
|
|
36
|
-
path: Path = typer.Argument(
|
|
37
|
-
default=Path("."),
|
|
38
|
-
help="Target project directory to analyze.",
|
|
39
|
-
exists=True,
|
|
40
|
-
file_okay=False,
|
|
41
|
-
dir_okay=True,
|
|
42
|
-
readable=True,
|
|
43
|
-
resolve_path=True,
|
|
44
|
-
),
|
|
45
|
-
format: OutputFormat = typer.Option(
|
|
46
|
-
OutputFormat.MD,
|
|
47
|
-
"--format",
|
|
48
|
-
"-f",
|
|
49
|
-
help="Output format: 'md' (Markdown) or 'json' (MCP JSON).",
|
|
50
|
-
case_sensitive=False,
|
|
51
|
-
),
|
|
52
|
-
output: Optional[Path] = typer.Option(
|
|
53
|
-
None,
|
|
54
|
-
"--output",
|
|
55
|
-
"-o",
|
|
56
|
-
help="Custom output file path (e.g. context/agent.md or custom.json).",
|
|
57
|
-
),
|
|
58
|
-
max_depth: int = typer.Option(
|
|
59
|
-
3,
|
|
60
|
-
"--max-depth",
|
|
61
|
-
"-d",
|
|
62
|
-
help="Maximum directory depth to scan.",
|
|
63
|
-
min=1,
|
|
64
|
-
max=10,
|
|
65
|
-
),
|
|
66
|
-
) -> None:
|
|
67
|
-
"""
|
|
68
|
-
Scan a project, build an AST-powered dependency graph, and generate LLM context.
|
|
69
|
-
"""
|
|
70
|
-
target_dir = path.resolve()
|
|
71
|
-
|
|
72
|
-
console.print(
|
|
73
|
-
Panel.fit(
|
|
74
|
-
f"[bold cyan]⚡ context-gen-cli (Python Edition)[/bold cyan]\n"
|
|
75
|
-
f"[dim]Analyzing target:[/dim] [green]{target_dir}[/green]\n"
|
|
76
|
-
f"[dim]Format:[/dim] [yellow]{format.value.upper()}[/yellow]",
|
|
77
|
-
border_style="cyan"
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
with console.status("[bold green]Scanning directory and parsing AST graph...[/bold green]"):
|
|
82
|
-
scan_result = scan_project(str(target_dir), max_depth=max_depth)
|
|
83
|
-
files = scan_result["files"]
|
|
84
|
-
tree = scan_result["tree"]
|
|
85
|
-
|
|
86
|
-
metadata = extract_metadata(str(target_dir), files)
|
|
87
|
-
graph = build_dependency_graph(files, str(target_dir))
|
|
88
|
-
|
|
89
|
-
# Determine default destination if not provided
|
|
90
|
-
if output:
|
|
91
|
-
out_file = output.resolve()
|
|
92
|
-
else:
|
|
93
|
-
context_dir = target_dir / "context"
|
|
94
|
-
context_dir.mkdir(parents=True, exist_ok=True)
|
|
95
|
-
filename = f"agent.{format.value}"
|
|
96
|
-
out_file = context_dir / filename
|
|
97
|
-
|
|
98
|
-
out_file.parent.mkdir(parents=True, exist_ok=True)
|
|
99
|
-
|
|
100
|
-
if format == OutputFormat.JSON:
|
|
101
|
-
json_data = generate_agent_json(metadata, graph, tree, str(target_dir))
|
|
102
|
-
out_file.write_text(json.dumps(json_data, indent=2), encoding="utf-8")
|
|
103
|
-
else:
|
|
104
|
-
md_text = generate_agent_md(metadata, graph, tree)
|
|
105
|
-
out_file.write_text(md_text, encoding="utf-8")
|
|
106
|
-
|
|
107
|
-
# Display completion summary
|
|
108
|
-
table = Table(show_header=False, box=None)
|
|
109
|
-
table.add_row("[bold]Scanned Files:[/bold]", f"[cyan]{len(files)}[/cyan]")
|
|
110
|
-
table.add_row("[bold]AST Graph Edges:[/bold]", f"[cyan]{len(graph['edges'])}[/cyan]")
|
|
111
|
-
table.add_row("[bold]Tech Stack:[/bold]", f"[green]{', '.join(metadata['techStack'])}[/green]")
|
|
112
|
-
table.add_row("[bold]Output File:[/bold]", f"[yellow]{out_file}[/yellow]")
|
|
113
|
-
|
|
114
|
-
console.print(
|
|
115
|
-
Panel(
|
|
116
|
-
table,
|
|
117
|
-
title="[bold green]✅ Context Generated Successfully[/bold green]",
|
|
118
|
-
border_style="green"
|
|
119
|
-
)
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if __name__ == "__main__":
|
|
124
|
-
app()
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: context-gen-cli
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: A modern CLI tool that scans any project, builds an AST-based dependency graph, and generates structured LLM context (agent.md / agent.json).
|
|
5
|
-
Author: yakkshit
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Keywords: llm,context,agent,cli,code-analysis,ast,graph,mcp
|
|
8
|
-
Classifier: Development Status :: 4 - Beta
|
|
9
|
-
Classifier: Environment :: Console
|
|
10
|
-
Classifier: Intended Audience :: Developers
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
-
Requires-Python: >=3.9
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
Requires-Dist: typer[all]>=0.12.0
|
|
21
|
-
Requires-Dist: rich>=13.7.0
|
|
22
|
-
Requires-Dist: pathspec>=0.12.1
|
|
23
|
-
Provides-Extra: dev
|
|
24
|
-
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
25
|
-
Requires-Dist: build>=1.1.0; extra == "dev"
|
|
26
|
-
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
27
|
-
|
|
28
|
-
# context-gen-cli (Python Edition)
|
|
29
|
-
|
|
30
|
-
> ⚡ Fast, AST-powered CLI tool that scans any project, extracts architecture models, and generates structured LLM context (`agent.md` & `agent.json`).
|
|
31
|
-
|
|
32
|
-
## Features
|
|
33
|
-
- **100% Accurate Python Dependency Graphs**: Built using Python's native `ast` (Abstract Syntax Tree) module.
|
|
34
|
-
- **Gitignore Respect**: Uses `pathspec` to ignore unwanted directories and secrets.
|
|
35
|
-
- **Dual Output**: Generates both human-readable Markdown (`agent.md`) and MCP-compatible structured JSON (`agent.json`).
|
|
36
|
-
- **Modern CLI**: Powered by `typer` and `rich`.
|
|
37
|
-
|
|
38
|
-
## Installation
|
|
39
|
-
```bash
|
|
40
|
-
pip install context-gen-cli
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Quick Start
|
|
44
|
-
```bash
|
|
45
|
-
# Generate agent.md in context/ directory
|
|
46
|
-
context-gen .
|
|
47
|
-
|
|
48
|
-
# Generate agent.json
|
|
49
|
-
context-gen . --format json
|
|
50
|
-
|
|
51
|
-
# Custom output path
|
|
52
|
-
context-gen ./my-project -o custom/path/context.md
|
|
53
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{context_gen_cli-1.0.0 → context_gen_cli-1.2.0}/context_gen_cli.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|