Remove list_files tool
This commit is contained in:
30
nanocode.py
30
nanocode.py
@@ -24,7 +24,7 @@ MAGENTA = "\033[35m"
|
||||
|
||||
|
||||
def read_file(path: str, offset: int = 0, limit: int = None) -> str:
|
||||
"""Read file contents with line numbers.
|
||||
"""[EXTERNAL FILESYSTEM] Read file contents from disk with line numbers.
|
||||
|
||||
Args:
|
||||
path: Path to the file to read
|
||||
@@ -45,7 +45,7 @@ def read_file(path: str, offset: int = 0, limit: int = None) -> str:
|
||||
|
||||
|
||||
def write_file(path: str, content: str) -> str:
|
||||
"""Write content to a file.
|
||||
"""[EXTERNAL FILESYSTEM] Write content to a file on disk (creates or overwrites).
|
||||
|
||||
Args:
|
||||
path: Path to the file to write
|
||||
@@ -72,7 +72,7 @@ def write_file(path: str, content: str) -> str:
|
||||
|
||||
|
||||
def edit_file(path: str, old: str, new: str, replace_all: bool = False) -> str:
|
||||
"""Replace text in a file.
|
||||
"""[EXTERNAL FILESYSTEM] Replace text in a file on disk.
|
||||
|
||||
Args:
|
||||
path: Path to the file to edit
|
||||
@@ -98,9 +98,9 @@ def edit_file(path: str, old: str, new: str, replace_all: bool = False) -> str:
|
||||
|
||||
|
||||
def glob_files(pattern: str, path: str = ".") -> str:
|
||||
"""Find files by filename matching a glob pattern, sorted by modification time.
|
||||
"""[EXTERNAL FILESYSTEM] Find files on disk matching a glob pattern.
|
||||
|
||||
Respects .gitignore files automatically via ripgrep.
|
||||
Respects .gitignore files automatically via ripgrep. Sorted by modification time.
|
||||
|
||||
Args:
|
||||
pattern: Glob pattern to match (e.g., '**/*.py')
|
||||
@@ -128,7 +128,7 @@ def glob_files(pattern: str, path: str = ".") -> str:
|
||||
|
||||
|
||||
def grep_files(pattern: str, path: str = ".", glob: str = None, max_results: int = 50) -> str:
|
||||
"""Search files for a regex pattern using ripgrep.
|
||||
"""[EXTERNAL FILESYSTEM] Search files on disk for a regex pattern using ripgrep.
|
||||
|
||||
Args:
|
||||
pattern: Regular expression pattern to search for
|
||||
@@ -160,7 +160,7 @@ def grep_files(pattern: str, path: str = ".", glob: str = None, max_results: int
|
||||
|
||||
|
||||
def run_bash(cmd: str) -> str:
|
||||
"""Run a shell command and return output.
|
||||
"""[EXTERNAL SYSTEM] Run a shell command on the host machine.
|
||||
|
||||
Args:
|
||||
cmd: Shell command to execute
|
||||
@@ -204,7 +204,21 @@ class RLMReasoningCallback(BaseCallback):
|
||||
|
||||
|
||||
class CodingAssistant(dspy.Signature):
|
||||
"""You are a concise coding assistant with access to sub agents."""
|
||||
"""You are a concise coding assistant.
|
||||
|
||||
CRITICAL - Two execution environments exist:
|
||||
|
||||
1. INTERNAL REPL (sandbox): Standard Python code you write executes in an isolated sandbox. Variables persist between iterations. Use for data processing, string manipulation, logic, loops, etc.
|
||||
|
||||
2. EXTERNAL TOOLS (real system): Functions like read_file(), write_file(), run_bash(), glob_files(), grep_files() execute OUTSIDE the sandbox on the real filesystem and host machine. These have real, persistent side effects.
|
||||
|
||||
When you need to:
|
||||
- Process data, do math, manipulate strings, iterate → write Python code directly in the REPL
|
||||
- Read/write actual files on disk → call read_file(), write_file(), edit_file()
|
||||
- Run shell commands on the host → call run_bash()
|
||||
- Search the codebase → call glob_files(), grep_files()
|
||||
|
||||
Do NOT confuse REPL variables with external files. Reading a file into a variable does not mean the variable updates if the file changes - you must call read_file() again."""
|
||||
|
||||
task: str = dspy.InputField(desc="The user's coding task or question")
|
||||
answer: str = dspy.OutputField(
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"train": [],
|
||||
"demos": [],
|
||||
"signature": {
|
||||
"instructions": "You are a concise coding assistant with access to sub agents.\n\nYou are tasked with producing the following outputs given the inputs `task`:\n- {answer}\n\nYou have access to a Python REPL environment. Write Python code and it will be executed. You will see the output, then write more code based on what you learned. This is an iterative process.\n\nAvailable:\n- Variables: `task` (your input data)\n- `llm_query(prompt)` - query a sub-LLM (~500K char capacity) for semantic analysis\n- `llm_query_batched(prompts)` - query multiple prompts concurrently (much faster for multiple queries)\n- `print()` - ALWAYS print to see results\n- `SUBMIT(answer)` - submit final output when done\n- Standard libraries: re, json, collections, math, etc.\n\nIMPORTANT: This is ITERATIVE. Each code block you write will execute, you'll see the output, then you decide what to do next. Do NOT try to solve everything in one step.\n\n1. EXPLORE FIRST - Look at your data before processing it. Print samples, check types/lengths, understand the structure.\n2. ITERATE - Write small code snippets, observe outputs, then decide next steps. State persists between iterations.\n3. VERIFY BEFORE SUBMITTING - If results seem wrong (zeros, empty, unexpected), reconsider your approach.\n4. USE llm_query FOR SEMANTICS - String matching finds WHERE things are; llm_query understands WHAT things mean.\n5. MINIMIZE RETYPING (INPUTS & OUTPUTS) - When values are long, precise, or error-prone (IDs, numbers, code, quotes), re-access them via variables and parse/compute in code instead of retyping. Use small, targeted prints to sanity-check, but avoid manual copying when variables can carry the exact value.\n6. SUBMIT ONLY AFTER SEEING OUTPUTS - SUBMIT ends the current run immediately. If you need to inspect printed output, run it in one step, review the result, then call SUBMIT in a later step.\n\nYou have max 50 sub-LLM calls. When done, call SUBMIT() with your output.\nAdditional tools available (use these instead of standard library equivalents):\n- `read_file(path: str, offset: int, limit: int) -> str` - Read file contents with line numbers.\n- `write_file(path: str, content: str) -> str` - Write content to a file.\n- `edit_file(path: str, old: str, new: str, replace_all: bool) -> str` - Replace text in a file.\n- `glob_files(pattern: str, path: str) -> str` - Find files by filename matching a glob pattern, sorted by modification time.\n- `grep_files(pattern: str, path: str, glob: str, max_results: int) -> str` - Search files for a regex pattern using ripgrep.\n- `run_bash(cmd: str) -> str` - Run a shell command and return output.",
|
||||
"instructions": "You are a concise coding assistant.\n\nCRITICAL - Two execution environments exist:\n\n1. INTERNAL REPL (sandbox): Standard Python code you write executes in an isolated sandbox. Variables persist between iterations. Use for data processing, string manipulation, logic, loops, etc.\n\n2. EXTERNAL TOOLS (real system): Functions like read_file(), write_file(), run_bash(), glob_files(), grep_files() execute OUTSIDE the sandbox on the real filesystem and host machine. These have real, persistent side effects.\n\nWhen you need to:\n- Process data, do math, manipulate strings, iterate \u2192 write Python code directly in the REPL\n- Read/write actual files on disk \u2192 call read_file(), write_file(), edit_file()\n- Run shell commands on the host \u2192 call run_bash()\n- Search the codebase \u2192 call glob_files(), grep_files()\n\nDo NOT confuse REPL variables with external files. Reading a file into a variable does not mean the variable updates if the file changes - you must call read_file() again.\n\nYou are tasked with producing the following outputs given the inputs `task`:\n- {answer}\n\nYou have access to a Python REPL environment. Write Python code and it will be executed. You will see the output, then write more code based on what you learned. This is an iterative process.\n\nAvailable:\n- Variables: `task` (your input data)\n- `llm_query(prompt)` - query a sub-LLM (~500K char capacity) for semantic analysis\n- `llm_query_batched(prompts)` - query multiple prompts concurrently (much faster for multiple queries)\n- `print()` - ALWAYS print to see results\n- `SUBMIT(answer)` - submit final output when done\n- Standard libraries: re, json, collections, math, etc.\n\nIMPORTANT: This is ITERATIVE. Each code block you write will execute, you'll see the output, then you decide what to do next. Do NOT try to solve everything in one step.\n\n1. EXPLORE FIRST - Look at your data before processing it. Print samples, check types/lengths, understand the structure.\n2. ITERATE - Write small code snippets, observe outputs, then decide next steps. State persists between iterations.\n3. VERIFY BEFORE SUBMITTING - If results seem wrong (zeros, empty, unexpected), reconsider your approach.\n4. USE llm_query FOR SEMANTICS - String matching finds WHERE things are; llm_query understands WHAT things mean.\n5. MINIMIZE RETYPING (INPUTS & OUTPUTS) - When values are long, precise, or error-prone (IDs, numbers, code, quotes), re-access them via variables and parse/compute in code instead of retyping. Use small, targeted prints to sanity-check, but avoid manual copying when variables can carry the exact value.\n6. SUBMIT ONLY AFTER SEEING OUTPUTS - SUBMIT ends the current run immediately. If you need to inspect printed output, run it in one step, review the result, then call SUBMIT in a later step.\n\nYou have max 50 sub-LLM calls. When done, call SUBMIT() with your output.\nAdditional tools available (use these instead of standard library equivalents):\n- `read_file(path: str, offset: int, limit: int) -> str` - [EXTERNAL FILESYSTEM] Read file contents from disk with line numbers.\n- `write_file(path: str, content: str) -> str` - [EXTERNAL FILESYSTEM] Write content to a file on disk (creates or overwrites).\n- `edit_file(path: str, old: str, new: str, replace_all: bool) -> str` - [EXTERNAL FILESYSTEM] Replace text in a file on disk.\n- `glob_files(pattern: str, path: str) -> str` - [EXTERNAL FILESYSTEM] Find files on disk matching a glob pattern.\n- `grep_files(pattern: str, path: str, glob: str, max_results: int) -> str` - [EXTERNAL FILESYSTEM] Search files on disk for a regex pattern using ripgrep.\n- `run_bash(cmd: str) -> str` - [EXTERNAL SYSTEM] Run a shell command on the host machine.",
|
||||
"fields": [
|
||||
{
|
||||
"prefix": "Variables Info:",
|
||||
@@ -47,7 +47,7 @@
|
||||
"train": [],
|
||||
"demos": [],
|
||||
"signature": {
|
||||
"instructions": "The trajectory was generated with the following objective: \nYou are a concise coding assistant with access to sub agents.\n\n\nBased on the REPL trajectory, extract the final outputs now.\n\n Review your trajectory to see what information you gathered and what values you computed, then provide the final outputs.",
|
||||
"instructions": "The trajectory was generated with the following objective: \nYou are a concise coding assistant.\n\nCRITICAL - Two execution environments exist:\n\n1. INTERNAL REPL (sandbox): Standard Python code you write executes in an isolated sandbox. Variables persist between iterations. Use for data processing, string manipulation, logic, loops, etc.\n\n2. EXTERNAL TOOLS (real system): Functions like read_file(), write_file(), run_bash(), glob_files(), grep_files() execute OUTSIDE the sandbox on the real filesystem and host machine. These have real, persistent side effects.\n\nWhen you need to:\n- Process data, do math, manipulate strings, iterate \u2192 write Python code directly in the REPL\n- Read/write actual files on disk \u2192 call read_file(), write_file(), edit_file()\n- Run shell commands on the host \u2192 call run_bash()\n- Search the codebase \u2192 call glob_files(), grep_files()\n\nDo NOT confuse REPL variables with external files. Reading a file into a variable does not mean the variable updates if the file changes - you must call read_file() again.\n\n\nBased on the REPL trajectory, extract the final outputs now.\n\n Review your trajectory to see what information you gathered and what values you computed, then provide the final outputs.",
|
||||
"fields": [
|
||||
{
|
||||
"prefix": "Variables Info:",
|
||||
|
||||
Reference in New Issue
Block a user