diff --git a/README.md b/README.md index fe29744..90a080f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Built using Claude Code, then used to build itself. - Tools: `read`, `write`, `edit`, `glob`, `grep`, `bash` - Conversation history - Colored terminal output +- Enhanced system context (OS, Python version, shell, available tools) ## Usage @@ -40,6 +41,7 @@ python nanocode.py ## Commands - `/c` - Clear conversation +- `/i` - Show system information - `/q` or `exit` - Quit ## Tools diff --git a/__pycache__/nanocode.cpython-311.pyc b/__pycache__/nanocode.cpython-311.pyc new file mode 100644 index 0000000..346b094 Binary files /dev/null and b/__pycache__/nanocode.cpython-311.pyc differ diff --git a/nanocode.py b/nanocode.py old mode 100755 new mode 100644 index bbe0bf5..695e6f8 --- a/nanocode.py +++ b/nanocode.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """nanocode - minimal claude code alternative""" -import glob as globlib, json, os, re, subprocess, urllib.request +import glob as globlib, json, os, platform, re, shutil, subprocess, sys, urllib.request OPENROUTER_KEY = os.environ.get("OPENROUTER_API_KEY") API_URL = "https://openrouter.ai/api/v1/messages" if OPENROUTER_KEY else "https://api.anthropic.com/v1/messages" @@ -18,6 +18,38 @@ ) +# --- System information --- + + +def get_system_info(): + """Gather system information to help LLM provide contextually appropriate responses.""" + info_parts = [] + + # Operating system + os_name = platform.system() + info_parts.append(f"OS: {os_name}") + + # Python version + py_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" + info_parts.append(f"Python: {py_version}") + + # Shell + shell = os.environ.get("SHELL", os.environ.get("COMSPEC", "unknown")) + shell_name = os.path.basename(shell) if shell != "unknown" else "unknown" + info_parts.append(f"Shell: {shell_name}") + + # Current working directory + info_parts.append(f"CWD: {os.getcwd()}") + + # Check for common development tools + tools = ["git", "npm", "node", "pip", "docker", "make"] + available = [t for t in tools if shutil.which(t)] + if available: + info_parts.append(f"Tools: {', '.join(available)}") + + return " | ".join(info_parts) + + # --- Tool implementations --- @@ -198,9 +230,12 @@ def render_markdown(text): def main(): + system_info = get_system_info() print(f"{BOLD}nanocode{RESET} | {DIM}{MODEL} ({'OpenRouter' if OPENROUTER_KEY else 'Anthropic'}) | {os.getcwd()}{RESET}\n") messages = [] - system_prompt = f"Concise coding assistant. cwd: {os.getcwd()}" + system_prompt = f"""Concise coding assistant. +{system_info} +Provide OS-appropriate commands and file paths based on the system information above.""" while True: try: @@ -215,6 +250,9 @@ def main(): messages = [] print(f"{GREEN}⏺ Cleared conversation{RESET}") continue + if user_input == "/i": + print(f"{CYAN}⏺ System Info:{RESET}\n {system_info}") + continue messages.append({"role": "user", "content": user_input})