change signature
This commit is contained in:
60
nanocode.py
60
nanocode.py
@@ -53,7 +53,8 @@ def write_file(path: str, content: str) -> str:
|
||||
Returns:
|
||||
'ok' on success
|
||||
"""
|
||||
print(f"{MAGENTA}⏺ Writing file: {path}{RESET}")
|
||||
print(f"{MAGENTA}⏺ Creating file: {path}{RESET}")
|
||||
|
||||
with open(path, "w") as f:
|
||||
f.write(content)
|
||||
return "ok"
|
||||
@@ -72,6 +73,7 @@ def edit_file(path: str, old: str, new: str, replace_all: bool = False) -> str:
|
||||
'ok' on success, error message on failure
|
||||
"""
|
||||
print(f"{MAGENTA}⏺ Editing file: {path}{RESET}")
|
||||
|
||||
text = open(path).read()
|
||||
if old not in text:
|
||||
return "error: old_string not found"
|
||||
@@ -94,7 +96,8 @@ def glob_files(pattern: str, path: str = ".") -> str:
|
||||
Returns:
|
||||
Newline-separated list of matching files
|
||||
"""
|
||||
print(f"{MAGENTA}⏺ Finding files with pattern: {pattern}{RESET}")
|
||||
print(f"{MAGENTA}⏺ Glob: {pattern}{RESET}")
|
||||
|
||||
full_pattern = (path + "/" + pattern).replace("//", "/")
|
||||
files = globlib.glob(full_pattern, recursive=True)
|
||||
files = sorted(
|
||||
@@ -115,7 +118,7 @@ def grep_files(pattern: str, path: str = ".") -> str:
|
||||
Returns:
|
||||
Matching lines in format 'filepath:line_num:content'
|
||||
"""
|
||||
print(f"{MAGENTA}⏺ Searching for pattern: {pattern}{RESET}")
|
||||
print(f"{MAGENTA}⏺ Grep: {pattern}{RESET}")
|
||||
regex = re.compile(pattern)
|
||||
hits = []
|
||||
for filepath in globlib.glob(path + "/**", recursive=True):
|
||||
@@ -140,7 +143,7 @@ def run_bash(cmd: str) -> str:
|
||||
Returns:
|
||||
Command output (stdout and stderr combined)
|
||||
"""
|
||||
print(f"{MAGENTA}⏺ Running command: {cmd}{RESET}")
|
||||
print(f"{MAGENTA}⏺ Bash: {cmd}{RESET}")
|
||||
proc = subprocess.Popen(
|
||||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
|
||||
)
|
||||
@@ -159,55 +162,6 @@ def run_bash(cmd: str) -> str:
|
||||
output_lines.append("\n(timed out after 30s)")
|
||||
return "".join(output_lines).strip() or "(empty output)"
|
||||
|
||||
|
||||
# --- Model selection ---
|
||||
|
||||
AVAILABLE_MODELS = {
|
||||
"1": ("GPT-5.2 Codex", "openai/gpt-5.2-codex"),
|
||||
"2": ("GPT-5.2", "openai/gpt-5.2"),
|
||||
"3": ("Claude Opus 4.5", "anthropic/claude-opus-4.5"),
|
||||
"4": ("Claude Opus 4", "anthropic/claude-opus-4"),
|
||||
"5": ("Qwen 3 Coder", "qwen/qwen3-coder"),
|
||||
"6": ("Gemini 3 Flash Preview", "google/gemini-3-flash-preview"),
|
||||
"7": ("Kimi K2 0905", "moonshotai/kimi-k2-0905"),
|
||||
"8": ("Minimax M2.1", "minimax/minimax-m2.1"),
|
||||
}
|
||||
|
||||
def select_model():
|
||||
"""Interactive model selection or use environment variable."""
|
||||
print(f"\n{BOLD}Select a model:{RESET}")
|
||||
for key, (name, model_id) in AVAILABLE_MODELS.items():
|
||||
print(f" {BLUE}{key}{RESET}. {name} ({DIM}{model_id}{RESET})")
|
||||
print(f" {BLUE}c{RESET}. Custom model (enter manually)")
|
||||
|
||||
while True:
|
||||
try:
|
||||
choice = (
|
||||
input(f"\n{BOLD}{BLUE}❯{RESET} Enter choice (1-8 or c): ")
|
||||
.strip()
|
||||
.lower()
|
||||
)
|
||||
|
||||
if choice in AVAILABLE_MODELS:
|
||||
name, model_id = AVAILABLE_MODELS[choice]
|
||||
print(f"{GREEN}⏺ Selected: {name}{RESET}")
|
||||
return model_id
|
||||
elif choice == "c":
|
||||
custom_model = input(
|
||||
f"{BOLD}{BLUE}❯{RESET} Enter model ID (e.g., openai/gpt-4): "
|
||||
).strip()
|
||||
if custom_model:
|
||||
print(f"{GREEN}⏺ Selected custom model: {custom_model}{RESET}")
|
||||
return custom_model
|
||||
else:
|
||||
print(f"{RED}⏺ Invalid model ID{RESET}")
|
||||
else:
|
||||
print(f"{RED}⏺ Invalid choice. Please enter 1-8 or c{RESET}")
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print(f"\n{RED}⏺ Model selection cancelled{RESET}")
|
||||
exit(1)
|
||||
|
||||
|
||||
class CodingAssistant(dspy.Signature):
|
||||
"""You are a concise coding assistant with access to sub agents."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user