- Add git policy section in system prompt (gadget.py): no auto git add/commit - Add policy warning in git_operation tool description (coder.py) - LLM must ask user before running git add or git commit - Safe commands (git status, git diff, git log) can run without asking - When user asks to commit: show changes first, then wait for confirmation
58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
import os
|
|
|
|
|
|
def tools_mapping(schema, handler, name=None):
|
|
tool_name = name or schema["function"]["name"]
|
|
return {"name": tool_name, "schema": schema, "handler": handler}
|
|
|
|
|
|
def tool_schemas(tools_definition):
|
|
return [t["schema"] for t in tools_definition]
|
|
|
|
|
|
def tool_handlers(tools_definition):
|
|
return {t["name"]: t["handler"] for t in tools_definition}
|
|
|
|
|
|
def build_system_prompt(tools_definition):
|
|
lines = [
|
|
"You are a coding agent that assists with software engineering tasks. "
|
|
"You have access to the following tools:",
|
|
""
|
|
]
|
|
for i, tool in enumerate(tools_definition, 1):
|
|
name = tool["name"]
|
|
desc = tool["schema"]["function"]["description"]
|
|
lines.append(f"{i}. {name}: {desc}")
|
|
lines.extend([
|
|
"",
|
|
"Use tools by returning tool calls when needed. After receiving tool "
|
|
"results, continue your reasoning. When you have the final answer, "
|
|
"return it as plain text without tool calls.",
|
|
"",
|
|
f"Your workspace directory is: {os.getcwd()}. "
|
|
"All file operations are relative to this directory.",
|
|
"",
|
|
"⚠️ GIT POLICY — IMPORTANT:",
|
|
"- NEVER run 'git add' or 'git commit' automatically after making changes.",
|
|
"- After editing/creating files, always ASK the user first before committing.",
|
|
"- Only run git commands when the user explicitly asks you to commit.",
|
|
"- You may run 'git status', 'git diff', 'git log' freely to inspect state.",
|
|
"- When user asks to commit: show them the changes first, then wait for confirmation.",
|
|
"",
|
|
"RAG capabilities (knowledge retrieval):",
|
|
"- list_collections → see available collections & doc counts.",
|
|
"- create_collection → create a new collection for a new topic.",
|
|
"- delete_collection → permanently remove a collection and its data.",
|
|
"- inspect_collection → learn metadata fields before searching.",
|
|
"- search_knowledge → semantic search + optional metadata filter.",
|
|
"- store_knowledge → save docs with rich metadata for later use.",
|
|
"- ingest_files → read files (with glob patterns) into a collection, auto-chunking.",
|
|
"",
|
|
"You can create collections yourself! When you encounter a new topic,",
|
|
"use create_collection first, then store_knowledge or ingest_files to populate it.",
|
|
"Always inspect_collection to discover metadata keys before filtering."
|
|
])
|
|
return "\n".join(lines)
|
|
|