Files
anything-llm/server/utils/agents/aibitat/plugins/filesystem/write-file.js
Timothy Carambat 3dedcede34 Filesystem Agent Skill overhaul (#5260)
* wip

* collector parse fixes

* refactor for class and also operation for reading

* add skill management panel

* management panel + lint

* management panel + lint

* Hide skill in non-docker context

* add ask-prompt for edit tool calls

* fix dep

* fix execa pkg (unused in codebase)

* simplify search with ripgrep only and build deps

* Fs skill i18n (#5264)

i18n

* add copy file support

* fix translations
2026-03-26 14:07:46 -07:00

90 lines
3.1 KiB
JavaScript

const filesystem = require("./lib.js");
module.exports.FilesystemWriteFile = {
name: "filesystem-write-file",
plugin: function () {
return {
name: "filesystem-write-file",
setup(aibitat) {
aibitat.function({
super: aibitat,
name: this.name,
description:
"Create a new file or completely overwrite an existing file with new content. " +
"Use with caution as it will overwrite existing files without warning. " +
"Handles text content with proper encoding. Only works within allowed directories.",
examples: [
{
prompt: "Create a new config file with these settings",
call: JSON.stringify({
path: "config.json",
content: '{"debug": true, "port": 3000}',
}),
},
{
prompt: "Write a hello world Python script",
call: JSON.stringify({
path: "hello.py",
content: 'print("Hello, World!")',
}),
},
],
parameters: {
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
properties: {
path: {
type: "string",
description:
"The path where the file should be created or overwritten.",
},
content: {
type: "string",
description: "The content to write to the file.",
},
},
required: ["path", "content"],
additionalProperties: false,
},
handler: async function ({ path: filePath = "", content = "" }) {
try {
this.super.handlerProps.log(
`Using the filesystem-write-file tool.`
);
const validPath = await filesystem.validatePath(filePath);
this.super.introspect(
`${this.caller}: Writing to file ${filePath}`
);
if (this.super.requestToolApproval) {
const approval = await this.super.requestToolApproval({
skillName: this.name,
payload: { path: filePath, content },
description: "Write content to a file",
});
if (!approval.approved) {
this.super.introspect(
`${this.caller}: User rejected the ${this.name} request.`
);
return approval.message;
}
}
await filesystem.writeFileContent(validPath, content);
this.super.introspect(`Successfully wrote to ${filePath}`);
return `Successfully wrote to ${filePath}`;
} catch (e) {
this.super.handlerProps.log(
`filesystem-write-file error: ${e.message}`
);
this.super.introspect(`Error: ${e.message}`);
return `Error writing file: ${e.message}`;
}
},
});
},
};
},
};