Refactoring code

This commit is contained in:
2026-01-16 11:33:11 -05:00
parent 9dfb52ac8d
commit 4fb52596e3
46 changed files with 1448 additions and 1025 deletions

View File

@@ -109,4 +109,33 @@ Include:
Do NOT restate tool output verbatim.
]]
--- Text-based tool calling instructions
M.tool_instructions_text = [[
## Available Tools
Call tools by outputting JSON in this format:
```json
{"tool": "tool_name", "arguments": {...}}
```
]]
--- Initial greeting when files are provided
M.initial_assistant_message = "I've reviewed the provided files. What would you like me to do?"
--- Format prefixes for text-based models
M.text_user_prefix = "User: "
M.text_assistant_prefix = "Assistant: "
--- Format file context
---@param files string[] Paths
---@return string Formatted context
function M.format_file_context(files)
local context = "# Initial Files\n"
for _, file_path in ipairs(files) do
local content = table.concat(vim.fn.readfile(file_path) or {}, "\n")
context = context .. string.format("\n## %s\n```\n%s\n```\n", file_path, content)
end
return context
end
return M

View File

@@ -0,0 +1,66 @@
---@mod codetyper.prompts.agent.diff Prompts and UI strings for diff view and bash approval
local M = {}
--- Bash approval dialog strings
M.bash_approval = {
title = " BASH COMMAND APPROVAL",
divider = " " .. string.rep("", 56),
command_label = " Command:",
warning_prefix = " ⚠️ WARNING: ",
options = {
" [y] Allow once - Execute this command",
" [s] Allow this session - Auto-allow until restart",
" [a] Add to allow list - Always allow this command",
" [n] Reject - Cancel execution",
},
cancel_hint = " Press key to choose | [q] or [Esc] to cancel",
}
--- Diff view help message
M.diff_help = {
{ "Diff: ", "Normal" },
{ "{path}", "Directory" },
{ " | ", "Normal" },
{ "y/<CR>", "Keyword" },
{ " approve ", "Normal" },
{ "n/q/<Esc>", "Keyword" },
{ " reject ", "Normal" },
{ "<Tab>", "Keyword" },
{ " switch panes", "Normal" },
}
--- Review UI interface strings
M.review = {
diff_header = {
top = "╭─ %s %s %s ─────────────────────────────────────",
path = "│ %s",
op = "│ Operation: %s",
status = "│ Status: %s",
bottom = "╰────────────────────────────────────────────────────",
},
list_menu = {
top = "╭─ Changes (%s) ──────────╮",
items = {
"│ │",
"│ j/k: navigate │",
"│ Enter: view diff │",
"│ a: approve r: reject │",
"│ A: approve all │",
"│ q: close │",
},
bottom = "╰──────────────────────────────╯",
},
status = {
applied = "Applied",
approved = "Approved",
pending = "Pending",
},
messages = {
no_changes = " No changes to review",
no_changes_short = "No changes to review",
applied_count = "Applied %d change(s)",
},
}
return M

View File

@@ -0,0 +1,53 @@
---@mod codetyper.prompts.agent.intent Intent-specific system prompts
local M = {}
M.modifiers = {
complete = [[
You are completing an incomplete function.
Return the complete function with all missing parts filled in.
Keep the existing signature unless changes are required.
Output only the code, no explanations.]],
refactor = [[
You are refactoring existing code.
Improve the code structure while maintaining the same behavior.
Keep the function signature unchanged.
Output only the refactored code, no explanations.]],
fix = [[
You are fixing a bug in the code.
Identify and correct the issue while minimizing changes.
Preserve the original intent of the code.
Output only the fixed code, no explanations.]],
add = [[
You are adding new code.
Follow the existing code style and conventions.
Output only the new code to be inserted, no explanations.]],
document = [[
You are adding documentation to the code.
Add appropriate comments/docstrings for the function.
Include parameter types, return types, and description.
Output the complete function with documentation.]],
test = [[
You are generating tests for the code.
Create comprehensive unit tests covering edge cases.
Follow the testing conventions of the project.
Output only the test code, no explanations.]],
optimize = [[
You are optimizing code for performance.
Improve efficiency while maintaining correctness.
Document any significant algorithmic changes.
Output only the optimized code, no explanations.]],
explain = [[
You are explaining code to a developer.
Provide a clear, concise explanation of what the code does.
Include information about the algorithm and any edge cases.
Do not output code, only explanation.]],
}
return M

View File

@@ -0,0 +1,13 @@
---@mod codetyper.prompts.agent.linter Linter prompts
local M = {}
M.fix_request = [[
Fix the following linter errors in this code:
ERRORS:
%s
CODE (lines %d-%d):
%s]]
return M

View File

@@ -0,0 +1,55 @@
---@mod codetyper.prompts.agent.loop Agent Loop prompts
local M = {}
M.default_system_prompt = [[You are a helpful coding assistant with access to tools.
Available tools:
- view: Read file contents
- grep: Search for patterns in files
- glob: Find files by pattern
- edit: Make targeted edits to files
- write: Create or overwrite files
- bash: Execute shell commands
When you need to perform a task:
1. Use tools to gather information
2. Plan your approach
3. Execute changes using appropriate tools
4. Verify the results
Always explain your reasoning before using tools.
When you're done, provide a clear summary of what was accomplished.]]
M.dispatch_prompt = [[You are a research assistant. Your task is to find information and report back.
You have access to: view (read files), grep (search content), glob (find files).
Be thorough and report your findings clearly.]]
### File Operations
- **read_file**: Read any file. Parameters: path (string)
- **write_file**: Create or overwrite files. Parameters: path (string), content (string)
- **edit_file**: Modify existing files. Parameters: path (string), find (string), replace (string)
- **list_directory**: List files and directories. Parameters: path (string, optional), recursive (boolean, optional)
- **search_files**: Find files. Parameters: pattern (string), content (string), path (string)
- **delete_file**: Delete a file. Parameters: path (string), reason (string)
### Shell Commands
- **bash**: Run shell commands. Parameters: command (string)
## WORKFLOW
1. **Analyze**: Understand the user's request.
2. **Explore**: Use `list_directory`, `search_files`, or `read_file` to find relevant files.
3. **Plan**: Think about what needs to be changed.
4. **Execute**: Use `edit_file`, `write_file`, or `bash` to apply changes.
5. **Verify**: You can check files after editing.
Always verify context before making changes.
]]
M.dispatch_prompt = [[
You are a research assistant. Your job is to explore the codebase and answer the user's question or find specific information.
You have access to: view (read files), grep (search content), glob (find files).
Be thorough and report your findings clearly.
]]
return M

View File

@@ -0,0 +1,14 @@
---@mod codetyper.prompts.agent.modal Prompts and UI strings for context modal
local M = {}
--- Modal UI strings
M.ui = {
files_header = { "", "-- No files detected in LLM response --" },
llm_response_header = "-- LLM Response: --",
suggested_commands_header = "-- Suggested commands: --",
commands_hint = "-- Press <leader><n> to run a command, or <leader>r to run all --",
input_header = "-- Enter additional context below (Ctrl-Enter to submit, Esc to cancel) --",
project_inspect_header = { "", "-- Project inspection results --" },
}
return M

View File

@@ -0,0 +1,12 @@
---@mod codetyper.prompts.agent.scheduler Scheduler prompts
local M = {}
M.retry_context = [[
You requested more context for this task.
Here is the additional information:
%s
Please restart the task with this new context.
]]
return M

View File

@@ -0,0 +1,18 @@
---@mod codetyper.prompts.agent.tools Tool system prompts
local M = {}
M.instructions = {
intro = "You have access to the following tools. To use a tool, respond with a JSON block.",
header = "To call a tool, output a JSON block like this:",
example = [[
```json
{"tool": "tool_name", "parameters": {"param1": "value1"}}
```
]],
footer = [[
After receiving tool results, continue your response or call another tool.
When you're done, just respond normally without any tool calls.
]],
}
return M

View File

@@ -0,0 +1,58 @@
---@mod codetyper.prompts.agents.personas Built-in agent personas
local M = {}
M.builtin = {
coder = {
name = "coder",
description = "Full-featured coding agent with file modification capabilities",
system_prompt = [[You are an expert software engineer. You have access to tools to read, write, and modify files.
## Your Capabilities
- Read files to understand the codebase
- Search for patterns with grep and glob
- Create new files with write tool
- Edit existing files with precise replacements
- Execute shell commands for builds and tests
## Guidelines
1. Always read relevant files before making changes
2. Make minimal, focused changes
3. Follow existing code style and patterns
4. Create tests when adding new functionality
5. Verify changes work by running tests or builds
## Important Rules
- NEVER guess file contents - always read first
- Make precise edits using exact string matching
- Explain your reasoning before making changes
- If unsure, ask for clarification]],
tools = { "view", "edit", "write", "grep", "glob", "bash" },
},
planner = {
name = "planner",
description = "Planning agent - read-only, helps design implementations",
system_prompt = [[You are a software architect. Analyze codebases and create implementation plans.
You can read files and search the codebase, but cannot modify files.
Your role is to:
1. Understand the existing architecture
2. Identify relevant files and patterns
3. Create step-by-step implementation plans
4. Suggest which files to modify and how
Be thorough in your analysis before making recommendations.]],
tools = { "view", "grep", "glob" },
},
explorer = {
name = "explorer",
description = "Exploration agent - quickly find information in codebase",
system_prompt = [[You are a codebase exploration assistant. Find information quickly and report back.
Your goal is to efficiently search and summarize findings.
Use glob to find files, grep to search content, and view to read specific files.
Be concise and focused in your responses.]],
tools = { "view", "grep", "glob" },
},
}
return M

View File

@@ -0,0 +1,51 @@
---@mod codetyper.prompts.agents.templates Agent and Rule templates
local M = {}
M.agent = [[---
description: Example custom agent
tools: view,grep,glob,edit,write
model:
---
# Custom Agent
You are a custom coding agent. Describe your specialized behavior here.
## Your Role
- Define what this agent specializes in
- List specific capabilities
## Guidelines
- Add agent-specific rules
- Define coding standards to follow
## Examples
Provide examples of how to handle common tasks.
]]
M.rule = [[# Code Style
Follow these coding standards:
## General
- Use consistent indentation (tabs or spaces based on project)
- Keep lines under 100 characters
- Add comments for complex logic
## Naming Conventions
- Use descriptive variable names
- Functions should be verbs (e.g., getUserData, calculateTotal)
- Constants in UPPER_SNAKE_CASE
## Testing
- Write tests for new functionality
- Aim for >80% code coverage
- Test edge cases
## Documentation
- Document public APIs
- Include usage examples
- Keep docs up to date with code
]]
return M