Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ flowchart TD
| ------------ | --------------------------------------------------------- |
| `readFile` | Reads the contents of a file from disk |
| `writeFile` | Writes or overwrites a file on disk |
| `appendFile` | Appends content to a file on disk. |
| `deleteFile` | Deletes a file from disk |
| `listDir` | Lists all files in a directory |
| `fetchURL` | Fetches the content of a URL and returns it as plain text |
Expand Down
1 change: 1 addition & 0 deletions src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const SYSTEM_PROMPT = `
TOOL {"name":"listDir","args":{"path":"."}}-{"Reason":"user wants folder content."}
TOOL {"name":"readFile","args":{"path":"package.json"}}-{"Reason":"user wants file conetnt."}
TOOL {"name":"writeFile","args":{"path":"test.txt","content":"hello"}}-{"Reason":"user want to write in teh file."}
TOOL {"name":"appendFile","args":{"path":"test.txt","content":"hello"}}-{"Reason":"user wants to append content to the file."}
TOOL {"name":"deleteFile","args":{"path":"test.txt"}}-{"Reason":"user wants to delete the file."}
TOOL {"name":"fetchURL","args":{"url":"https://example.com"}}-{"Reason":"user asks about website content."}
TOOL {"name":"runCommand","args":{"command":"git status"}}-{"Reason":"user wants to inspect the repository state."}
Expand Down
26 changes: 18 additions & 8 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ function writeFile(path, content) {
}
}

function appendFile(path, content) {
try {
fs.appendFileSync(path, content, "utf8");
return "Content appended successfully to the file";
} catch (error) {
if (error.code === "EISDIR") {
return `"${path}" is a directory, not a file.`;
}

if (error.code === "ENOENT") {
return `Content could not be appended to file "${path}" because its directory does not exist.`;
}

throw error;
}
}

function deleteFile(path) {
try {
fs.unlinkSync(path);
Expand Down Expand Up @@ -136,11 +153,4 @@ function runCommand(command) {
}
}

module.exports = {
readFile,
writeFile,
deleteFile,
listDir,
fetchURL,
runCommand,
};
module.exports = { readFile, writeFile, appendFile, deleteFile, listDir, fetchURL, runCommand };
14 changes: 14 additions & 0 deletions src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ const tools = {
},
func: funcs.writeFile,
},
appendFile: {
description: "Appends content to the end of an existing file on the disk.",
parameters: {
path: {
type: "STRING",
description: "The path of the file in the disk, e.g. ~/home/resume.txt",
},
content: {
type: "STRING",
description: "The content to append to the file, e.g. Hello, World!",
},
},
func: funcs.appendFile,
},
deleteFile: {
description: "Deletes a file from the disk.",
parameters: {
Expand Down
Loading