companionbot 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tools/index.js +49 -0
- package/package.json +1 -1
package/dist/tools/index.js
CHANGED
|
@@ -117,6 +117,28 @@ export const tools = [
|
|
|
117
117
|
required: ["path", "content"],
|
|
118
118
|
},
|
|
119
119
|
},
|
|
120
|
+
{
|
|
121
|
+
name: "edit_file",
|
|
122
|
+
description: "Edit a file by replacing exact text. The oldText must match exactly (including whitespace). Use this for precise, surgical edits instead of rewriting the entire file.",
|
|
123
|
+
input_schema: {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: {
|
|
126
|
+
path: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "The absolute path to the file to edit",
|
|
129
|
+
},
|
|
130
|
+
oldText: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Exact text to find and replace (must match exactly including whitespace)",
|
|
133
|
+
},
|
|
134
|
+
newText: {
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "New text to replace the old text with",
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
required: ["path", "oldText", "newText"],
|
|
140
|
+
},
|
|
141
|
+
},
|
|
120
142
|
{
|
|
121
143
|
name: "list_directory",
|
|
122
144
|
description: "List files and directories in a given path.",
|
|
@@ -598,6 +620,32 @@ export async function executeTool(name, input) {
|
|
|
598
620
|
await fs.writeFile(filePath, content, "utf-8");
|
|
599
621
|
return `File written successfully: ${filePath}`;
|
|
600
622
|
}
|
|
623
|
+
case "edit_file": {
|
|
624
|
+
const filePath = input.path;
|
|
625
|
+
const oldText = input.oldText;
|
|
626
|
+
const newText = input.newText;
|
|
627
|
+
if (!isPathAllowed(filePath)) {
|
|
628
|
+
return `Error: Access denied. Path not in allowed directories.`;
|
|
629
|
+
}
|
|
630
|
+
// 파일 읽기
|
|
631
|
+
let content;
|
|
632
|
+
try {
|
|
633
|
+
content = await fs.readFile(filePath, "utf-8");
|
|
634
|
+
}
|
|
635
|
+
catch (error) {
|
|
636
|
+
return `Error: Could not read file "${filePath}". ${error instanceof Error ? error.message : String(error)}`;
|
|
637
|
+
}
|
|
638
|
+
// oldText 찾기
|
|
639
|
+
const index = content.indexOf(oldText);
|
|
640
|
+
if (index === -1) {
|
|
641
|
+
return `Error: oldText not found in file. Make sure the text matches exactly (including whitespace).`;
|
|
642
|
+
}
|
|
643
|
+
// 첫 번째만 교체
|
|
644
|
+
const newContent = content.slice(0, index) + newText + content.slice(index + oldText.length);
|
|
645
|
+
// 저장
|
|
646
|
+
await fs.writeFile(filePath, newContent, "utf-8");
|
|
647
|
+
return `File edited successfully: ${filePath}`;
|
|
648
|
+
}
|
|
601
649
|
case "list_directory": {
|
|
602
650
|
const dirPath = input.path;
|
|
603
651
|
if (!isPathAllowed(dirPath)) {
|
|
@@ -1207,6 +1255,7 @@ export function getToolsDescription(modelId) {
|
|
|
1207
1255
|
## 파일 작업
|
|
1208
1256
|
- read_file: 파일 읽기
|
|
1209
1257
|
- write_file: 파일 생성/수정
|
|
1258
|
+
- edit_file: 파일의 특정 부분만 수정 (oldText → newText, 정확히 일치해야 함)
|
|
1210
1259
|
- list_directory: 디렉토리 탐색
|
|
1211
1260
|
|
|
1212
1261
|
## 시스템
|