Compare commits
No commits in common. "a27e3da769dd9ba3247db30e9ea3818d97f4ab79" and "50ba937ae0e725dbfd8d69d8dbe798e654a2658b" have entirely different histories.
a27e3da769
...
50ba937ae0
3 changed files with 4 additions and 63 deletions
|
|
@ -292,59 +292,6 @@ local M = {
|
||||||
- Never do write operations on a file which you have not read before. Its contents must be in your context before writing. This does not apply if you create a new file.
|
- Never do write operations on a file which you have not read before. Its contents must be in your context before writing. This does not apply if you create a new file.
|
||||||
- The plugin will verify the `project_name` is correct before running any tools.
|
- The plugin will verify the `project_name` is correct before running any tools.
|
||||||
- If the response grows too large, I'll guide you to break it into smaller steps.
|
- If the response grows too large, I'll guide you to break it into smaller steps.
|
||||||
|
|
||||||
You are assisting me in a coding workflow for a project (e.g., "my_project").
|
|
||||||
|
|
||||||
1. **Gather Context / Ask Questions**
|
|
||||||
- If you need more information or something is unclear, **ask me directly** in plain text, without calling any tools.
|
|
||||||
|
|
||||||
2. **Inspect Files**
|
|
||||||
- When you need to check a file’s content, use:
|
|
||||||
```yaml
|
|
||||||
project_name: "my_project"
|
|
||||||
tools:
|
|
||||||
- tool: "readFile"
|
|
||||||
path: "relative/path/to/file"
|
|
||||||
```
|
|
||||||
- Read the file before deciding on any modifications.
|
|
||||||
|
|
||||||
3. **Make Changes**
|
|
||||||
- If you need to modify an existing file (after reading it), use:
|
|
||||||
```yaml
|
|
||||||
project_name: "my_project"
|
|
||||||
tools:
|
|
||||||
- tool: "editFile"
|
|
||||||
path: "relative/path/to/file"
|
|
||||||
content: |
|
|
||||||
# Full updated file content
|
|
||||||
```
|
|
||||||
- Or perform incremental text replacements with:
|
|
||||||
```yaml
|
|
||||||
project_name: "my_project"
|
|
||||||
tools:
|
|
||||||
- tool: "replace_in_file"
|
|
||||||
path: "relative/path/to/file"
|
|
||||||
replacements:
|
|
||||||
- search: "old text"
|
|
||||||
replace: "new text"
|
|
||||||
```
|
|
||||||
|
|
||||||
4. **Run Commands (Optional)**
|
|
||||||
- To run tests, list files, or do other checks, use:
|
|
||||||
```yaml
|
|
||||||
project_name: "my_project"
|
|
||||||
tools:
|
|
||||||
- tool: "executeCommand"
|
|
||||||
command: "shell command here"
|
|
||||||
```
|
|
||||||
|
|
||||||
5. **Important Rules**
|
|
||||||
- Always start with 1 or 2, but afterwards you can mix 1, 2, 3, and 4 as needed.
|
|
||||||
- Include `project_name: "my_project"` whenever you call `tools`.
|
|
||||||
- Keep each tool call in the `tools` array (multiple if needed).
|
|
||||||
- **Never write to a file you haven’t read** in this session (unless creating a new file).
|
|
||||||
- Follow secure coding guidelines (input validation, least privilege, no sensitive info in logs, etc.).
|
|
||||||
- When done, provide a final answer **without** calling any tools.
|
|
||||||
]],
|
]],
|
||||||
["secure-coding"] = [[
|
["secure-coding"] = [[
|
||||||
### Secure Coding Guidelines
|
### Secure Coding Guidelines
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,8 @@ local robust_lsp = require("chatgpt_nvim.tools.lsp_robust_diagnostics")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- Function to escape all Lua pattern magic characters:
|
-- Enhanced search_and_replace to track if a string was found. We use Lua’s gsub return value
|
||||||
local function escape_lua_pattern(s)
|
-- (updatedString, replacementCount) to see if any replacements occurred.
|
||||||
return s:gsub("([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function search_and_replace(original, replacements)
|
local function search_and_replace(original, replacements)
|
||||||
local updated = original
|
local updated = original
|
||||||
local info_msgs = {}
|
local info_msgs = {}
|
||||||
|
|
@ -16,11 +13,8 @@ local function search_and_replace(original, replacements)
|
||||||
local search_str = r.search or ""
|
local search_str = r.search or ""
|
||||||
local replace_str = r.replace or ""
|
local replace_str = r.replace or ""
|
||||||
|
|
||||||
-- Escape special pattern chars to ensure literal matching:
|
|
||||||
local escaped_search = escape_lua_pattern(search_str)
|
|
||||||
|
|
||||||
local replacement_count = 0
|
local replacement_count = 0
|
||||||
updated, replacement_count = updated:gsub(escaped_search, replace_str)
|
updated, replacement_count = updated:gsub(search_str, replace_str)
|
||||||
|
|
||||||
-- If the string was not found, append an info message
|
-- If the string was not found, append an info message
|
||||||
if replacement_count == 0 then
|
if replacement_count == 0 then
|
||||||
|
|
@ -47,8 +41,8 @@ M.run = function(tool_call, conf, prompt_user_tool_accept, is_subpath, read_file
|
||||||
if not path or #replacements == 0 then
|
if not path or #replacements == 0 then
|
||||||
return "[replace_in_file] Missing 'path' or 'replacements'."
|
return "[replace_in_file] Missing 'path' or 'replacements'."
|
||||||
end
|
end
|
||||||
|
|
||||||
local root = vim.fn.getcwd()
|
local root = vim.fn.getcwd()
|
||||||
|
|
||||||
if not is_subpath(root, path) then
|
if not is_subpath(root, path) then
|
||||||
return string.format("Tool [replace_in_file for '%s'] REJECTED. Path outside project root.", path)
|
return string.format("Tool [replace_in_file for '%s'] REJECTED. Path outside project root.", path)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue