ichiran 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ichiran/__init__.py +1 -0
- ichiran/__main__.py +4 -0
- ichiran/cli.py +69 -0
- ichiran/config.py +45 -0
- ichiran/display.py +142 -0
- ichiran/gemini.py +58 -0
- ichiran/interview.py +1052 -0
- ichiran/prompt.py +182 -0
- ichiran/scanner.py +213 -0
- ichiran/writer.py +51 -0
- ichiran-0.1.0.dist-info/METADATA +370 -0
- ichiran-0.1.0.dist-info/RECORD +16 -0
- ichiran-0.1.0.dist-info/WHEEL +5 -0
- ichiran-0.1.0.dist-info/entry_points.txt +2 -0
- ichiran-0.1.0.dist-info/licenses/LICENSE +21 -0
- ichiran-0.1.0.dist-info/top_level.txt +1 -0
ichiran/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
ichiran/__main__.py
ADDED
ichiran/cli.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from ichiran.config import get_api_key, load_api_key, reset_api_key
|
|
5
|
+
from ichiran.display import (
|
|
6
|
+
console,
|
|
7
|
+
print_banner,
|
|
8
|
+
print_info_box,
|
|
9
|
+
print_success,
|
|
10
|
+
print_warning,
|
|
11
|
+
)
|
|
12
|
+
from ichiran.gemini import generate_readme
|
|
13
|
+
from ichiran.interview import run_interview
|
|
14
|
+
from ichiran.writer import write_readme
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main():
|
|
18
|
+
parser = argparse.ArgumentParser(
|
|
19
|
+
prog="ichiran", description="AI-powered README generator"
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--reset", action="store_true", help="Reset your saved Gemini API key"
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"--version", action="store_true", help="Show the current version"
|
|
26
|
+
)
|
|
27
|
+
args = parser.parse_args()
|
|
28
|
+
|
|
29
|
+
if args.reset:
|
|
30
|
+
reset_api_key()
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
if args.version:
|
|
34
|
+
try:
|
|
35
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
36
|
+
console.print(f"[bold cyan]ichiran[/bold cyan] [white]v{version('ichiran')}[/white]")
|
|
37
|
+
except PackageNotFoundError:
|
|
38
|
+
console.print("[bold cyan]ichiran[/bold cyan] [white]v0.1.0[/white]")
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
# print banner — box 1
|
|
42
|
+
print_banner()
|
|
43
|
+
|
|
44
|
+
# print info box — box 2
|
|
45
|
+
existing_key = load_api_key()
|
|
46
|
+
print_info_box(cwd=os.getcwd(), api_key_loaded=bool(existing_key))
|
|
47
|
+
|
|
48
|
+
# ensure API key is available (prompts if missing)
|
|
49
|
+
get_api_key()
|
|
50
|
+
|
|
51
|
+
# run the interview
|
|
52
|
+
answers = run_interview()
|
|
53
|
+
|
|
54
|
+
if answers is None:
|
|
55
|
+
print_warning("Interview cancelled. No README was generated.")
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
# generate readme from answers + codebase scan
|
|
59
|
+
console.print("\n[dim]Scanning codebase and generating README...[/dim]")
|
|
60
|
+
readme_content = generate_readme(answers)
|
|
61
|
+
|
|
62
|
+
# write to file
|
|
63
|
+
write_readme(readme_content)
|
|
64
|
+
|
|
65
|
+
print_success("Done. Your README is ready.")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
main()
|
ichiran/config.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from dotenv import load_dotenv
|
|
6
|
+
|
|
7
|
+
from ichiran.display import print_info, print_success
|
|
8
|
+
|
|
9
|
+
CONFIG_DIR = Path.home() / ".config" / "ichiran"
|
|
10
|
+
CONFIG_FILE = CONFIG_DIR / "config.json"
|
|
11
|
+
|
|
12
|
+
load_dotenv(dotenv_path=".env.local") # always load, not conditionally
|
|
13
|
+
|
|
14
|
+
def save_api_key(api_key: str) -> None:
|
|
15
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
16
|
+
with open(CONFIG_FILE, "w") as f:
|
|
17
|
+
json.dump({"api_key": api_key}, f) # fixed: was "api.key"
|
|
18
|
+
|
|
19
|
+
def load_api_key() -> str | None:
|
|
20
|
+
if CONFIG_FILE.exists():
|
|
21
|
+
with open(CONFIG_FILE) as f:
|
|
22
|
+
data = json.load(f)
|
|
23
|
+
return data.get("api_key") # now matches save
|
|
24
|
+
return os.getenv("API_KEY")
|
|
25
|
+
|
|
26
|
+
def prompt_for_api_key() -> str:
|
|
27
|
+
print_info("No API key found...")
|
|
28
|
+
print_info("Get one at: https://aistudio.google.com/api-keys")
|
|
29
|
+
api_key = input("Enter your Gemini API Key: ").strip()
|
|
30
|
+
save_api_key(api_key)
|
|
31
|
+
print_success("API Key Saved...")
|
|
32
|
+
return api_key
|
|
33
|
+
|
|
34
|
+
def get_api_key() -> str:
|
|
35
|
+
api_key = load_api_key()
|
|
36
|
+
if not api_key:
|
|
37
|
+
api_key = prompt_for_api_key()
|
|
38
|
+
return api_key
|
|
39
|
+
|
|
40
|
+
def reset_api_key() -> None:
|
|
41
|
+
if CONFIG_FILE.exists():
|
|
42
|
+
CONFIG_FILE.unlink()
|
|
43
|
+
print_success("API key removed.")
|
|
44
|
+
else:
|
|
45
|
+
print_info("No saved API key was found.")
|
ichiran/display.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.panel import Panel
|
|
3
|
+
from rich.rule import Rule
|
|
4
|
+
from rich.table import Table
|
|
5
|
+
from rich.text import Text
|
|
6
|
+
|
|
7
|
+
console = Console()
|
|
8
|
+
|
|
9
|
+
ASCII_LOGO = """
|
|
10
|
+
|
|
11
|
+
██╗ ██████╗██╗ ██╗██╗██████╗ █████╗ ███╗ ██╗
|
|
12
|
+
██║██╔════╝██║ ██║██║██╔══██╗██╔══██╗████╗ ██║
|
|
13
|
+
██║██║ ███████║██║██████╔╝███████║██╔██╗ ██║
|
|
14
|
+
██║██║ ██╔══██║██║██╔══██╗██╔══██║██║╚██╗██║
|
|
15
|
+
██║╚██████╗██║ ██║██║██║ ██║██║ ██║██║ ╚████║
|
|
16
|
+
╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
TAGLINE = "AI-powered README generator"
|
|
21
|
+
VERSION = "v0.1.0"
|
|
22
|
+
AUTHOR = "ushiecodes"
|
|
23
|
+
GITHUB = "https://github.com/ushiecodes/ichiran.git"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def print_banner():
|
|
27
|
+
logo_text = Text(ASCII_LOGO, style="bold cyan", justify="left", no_wrap=True, overflow="crop")
|
|
28
|
+
tagline_text = Text(f"{TAGLINE} {VERSION}", style="italic white", justify="left")
|
|
29
|
+
meta = Text.assemble(
|
|
30
|
+
("by ", "dim white"),
|
|
31
|
+
(AUTHOR, "bold cyan"),
|
|
32
|
+
(" ", ""),
|
|
33
|
+
(GITHUB, f"link {GITHUB} cyan"),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
content = Table.grid(expand=True)
|
|
37
|
+
content.add_column(justify="left")
|
|
38
|
+
content.add_row(logo_text)
|
|
39
|
+
content.add_row(tagline_text)
|
|
40
|
+
content.add_row(meta)
|
|
41
|
+
|
|
42
|
+
console.print(Panel(content, border_style="cyan", padding=(0, 2), width=80))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def print_info_box(cwd: str, api_key_loaded: bool):
|
|
46
|
+
content = Table.grid(expand=True)
|
|
47
|
+
content.add_column()
|
|
48
|
+
|
|
49
|
+
content.add_row(Text(" How it works", style="bold white"))
|
|
50
|
+
content.add_row(Text.assemble((" 1 ", "bold cyan"), ("Answer questions about your project", "white")))
|
|
51
|
+
content.add_row(Text.assemble((" 2 ", "bold cyan"), ("Ichiran scans your codebase", "white")))
|
|
52
|
+
content.add_row(Text.assemble((" 3 ", "bold cyan"), ("Gemini AI generates a README.md", "white")))
|
|
53
|
+
content.add_row(Rule(style="dim white"))
|
|
54
|
+
content.add_row(Text.assemble((" Tip ", "bold cyan"), ("Type ", "dim white"), ("RTFM", "bold cyan"), (" on any question for help", "dim white")))
|
|
55
|
+
content.add_row(Rule(style="dim white"))
|
|
56
|
+
content.add_row(Text.assemble((" Running in ", "dim white"), (cwd, "cyan")))
|
|
57
|
+
|
|
58
|
+
if api_key_loaded:
|
|
59
|
+
content.add_row(Text.assemble((" ", ""), ("✔", "bold green"), (" API key loaded", "white")))
|
|
60
|
+
else:
|
|
61
|
+
content.add_row(Text.assemble((" ", ""), ("→", "bold blue"), (" No API key found — you will be prompted", "dim white")))
|
|
62
|
+
|
|
63
|
+
content.add_row(Text(""))
|
|
64
|
+
|
|
65
|
+
console.print(Panel(content, border_style="white", padding=(0, 1), width=80))
|
|
66
|
+
console.print("")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def print_phase_controls(phase_title: str):
|
|
70
|
+
content = Table.grid(expand=True)
|
|
71
|
+
content.add_column()
|
|
72
|
+
content.add_row(Text(f" {phase_title}", style="bold white"))
|
|
73
|
+
content.add_row(Rule(style="dim white"))
|
|
74
|
+
content.add_row(
|
|
75
|
+
Text.assemble(
|
|
76
|
+
(" SKIP ", "bold cyan"), ("skip ", "dim white"),
|
|
77
|
+
("TLDR ", "bold cyan"), ("generic ", "dim white"),
|
|
78
|
+
("RTFM ", "bold cyan"), ("help ", "dim white"),
|
|
79
|
+
("QUIT ", "bold cyan"), ("exit", "dim white"),
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
console.print(Panel(content, border_style="white", padding=(0, 1), width=80))
|
|
83
|
+
|
|
84
|
+
def print_question(text: str, hints: list):
|
|
85
|
+
console.print(f"\n[bold white]{text}[/bold white]")
|
|
86
|
+
for hint in hints:
|
|
87
|
+
console.print(f"[dim]{hint}[/dim]")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def print_rtfm(content: str):
|
|
91
|
+
console.print(
|
|
92
|
+
Panel(
|
|
93
|
+
f"[white]{content}[/white]",
|
|
94
|
+
title="[bold cyan] RTFM [/bold cyan]",
|
|
95
|
+
border_style="cyan",
|
|
96
|
+
padding=(1, 2),
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def print_layer_prompt():
|
|
102
|
+
console.print(
|
|
103
|
+
Panel(
|
|
104
|
+
"[bold white]Your README draft is ready and publishable as-is.[/bold white]\n\n"
|
|
105
|
+
" [bold cyan]Layer 2[/bold cyan] [dim]— usage guide, configuration reference, architecture[/dim]\n"
|
|
106
|
+
" [bold cyan]Layer 3[/bold cyan] [dim]— security, deployment, changelog, contributing guide[/dim]\n\n"
|
|
107
|
+
"[dim]Type [/dim][bold white]more[/bold white][dim] for both · "
|
|
108
|
+
"[/dim][bold white]layer 2[/bold white][dim] or [/dim][bold white]layer 3[/bold white]"
|
|
109
|
+
"[dim] for one · [/dim][bold white]done[/bold white][dim] to finish[/dim]",
|
|
110
|
+
border_style="cyan",
|
|
111
|
+
padding=(1, 2),
|
|
112
|
+
width=80,
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def print_success(message: str):
|
|
118
|
+
console.print(f"\n[bold green]✔[/bold green] [white]{message}[/white]")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def print_warning(message: str):
|
|
122
|
+
console.print(f"\n[bold yellow]⚠[/bold yellow] [yellow]{message}[/yellow]")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def print_error(message: str):
|
|
126
|
+
console.print(f"\n[bold red]✘[/bold red] [red]{message}[/red]")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def print_info(message: str):
|
|
130
|
+
console.print(f"\n[bold blue]→[/bold blue] [dim]{message}[/dim]")
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def print_audit_report(lines: list):
|
|
134
|
+
content = "\n".join(lines)
|
|
135
|
+
console.print(
|
|
136
|
+
Panel(
|
|
137
|
+
content,
|
|
138
|
+
title="[bold white] README Audit [/bold white]",
|
|
139
|
+
border_style="blue",
|
|
140
|
+
padding=(1, 2),
|
|
141
|
+
)
|
|
142
|
+
)
|
ichiran/gemini.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from google import genai
|
|
4
|
+
from google.genai.errors import ClientError
|
|
5
|
+
|
|
6
|
+
from ichiran.config import get_api_key
|
|
7
|
+
from ichiran.display import print_info, print_warning
|
|
8
|
+
from ichiran.interview import format_answers
|
|
9
|
+
from ichiran.prompt import SYSTEM_PROMPT
|
|
10
|
+
from ichiran.scanner import format_codebase_for_prompt, scan_codebase
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def generate_readme(answers: dict) -> str:
|
|
14
|
+
api_key = get_api_key()
|
|
15
|
+
client = genai.Client(api_key=api_key)
|
|
16
|
+
|
|
17
|
+
print_info("Scanning codebase...")
|
|
18
|
+
scan_result = scan_codebase(".")
|
|
19
|
+
codebase_context = format_codebase_for_prompt(scan_result)
|
|
20
|
+
|
|
21
|
+
formatted_answers = format_answers(answers)
|
|
22
|
+
|
|
23
|
+
full_prompt = f"""
|
|
24
|
+
{formatted_answers}
|
|
25
|
+
|
|
26
|
+
=== ACTUAL CODEBASE ===
|
|
27
|
+
{codebase_context}
|
|
28
|
+
|
|
29
|
+
Using both the interview answers AND the codebase above, generate a complete README.md following the system instructions exactly.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
print_info("Generating README...")
|
|
33
|
+
response = _call_with_retry(client, full_prompt)
|
|
34
|
+
return response
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _call_with_retry(client, prompt: str, retries: int = 3) -> str:
|
|
38
|
+
for attempt in range(retries):
|
|
39
|
+
try:
|
|
40
|
+
response = client.models.generate_content(
|
|
41
|
+
model="gemini-3.5-flash",
|
|
42
|
+
config={"system_instruction": SYSTEM_PROMPT},
|
|
43
|
+
contents=prompt
|
|
44
|
+
)
|
|
45
|
+
return response.text
|
|
46
|
+
|
|
47
|
+
except ClientError as e:
|
|
48
|
+
if "429" in str(e):
|
|
49
|
+
if attempt == retries - 1:
|
|
50
|
+
raise RuntimeError(
|
|
51
|
+
"Gemini rate limit hit after all retries. "
|
|
52
|
+
"Wait a few minutes and try again, or use a different API key."
|
|
53
|
+
) from e
|
|
54
|
+
wait = 2 ** (attempt + 1)
|
|
55
|
+
print_warning(f"Rate limited. Waiting {wait}s seconds before retry {attempt + 1}/{retries}...")
|
|
56
|
+
time.sleep(wait)
|
|
57
|
+
else:
|
|
58
|
+
raise
|