Skip to content

Commit ebc44b2

Browse files
agn-7claude
andcommitted
refactor(filesystem): rename write_or_update_file to create_or_append_file
Renames the tool, schema, and underlying function to accurately describe the behavior (create-or-append, not update/overwrite) per review feedback. - Tool: write_or_update_file -> create_or_append_file - Schema: WriteOrUpdateFileArgsSchema -> CreateOrAppendFileArgsSchema - Function: writeOrUpdateFileContent -> createOrAppendFileContent - README updated; tests updated; append_file description updated. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 54ed837 commit ebc44b2

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/filesystem/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ The server's directory access control follows this flow:
102102
- File must already exist - use `write_file` to create new files
103103
- Preserves existing content, adds new content at the end
104104

105-
- **write_or_update_file**
105+
- **create_or_append_file**
106106
- Create new file or append to existing file
107107
- Inputs:
108108
- `path` (string): File location
@@ -219,7 +219,7 @@ The mapping for filesystem tools is:
219219
| `create_directory` | `false` | `true` | `false` | Re‑creating the same dir is a no‑op |
220220
| `write_file` | `false` | `true` | `true` | Overwrites existing files |
221221
| `append_file` | `false` | `false` | `false` | Appends to existing files; not idempotent |
222-
| `write_or_update_file` | `false` | `false` | `false` | Creates or appends; behavior depends on state |
222+
| `create_or_append_file` | `false` | `false` | `false` | Creates or appends; behavior depends on state |
223223
| `edit_file` | `false` | `false` | `true` | Re‑applying edits can fail or double‑apply |
224224
| `move_file` | `false` | `false` | `true` | Deletes source file |
225225

src/filesystem/__tests__/lib.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
readFileContent,
1616
writeFileContent,
1717
appendFileContent,
18-
writeOrUpdateFileContent,
18+
createOrAppendFileContent,
1919
// Search & filtering functions
2020
searchFilesWithValidation,
2121
// File editing functions
@@ -344,14 +344,14 @@ describe('Lib Functions', () => {
344344
});
345345
});
346346

347-
describe('writeOrUpdateFileContent', () => {
347+
describe('createOrAppendFileContent', () => {
348348
it('creates new file if it does not exist', async () => {
349349
const error = new Error('ENOENT');
350350
(error as any).code = 'ENOENT';
351351
mockFs.appendFile.mockRejectedValue(error);
352352
mockFs.writeFile.mockResolvedValue(undefined);
353353

354-
await writeOrUpdateFileContent('/test/newfile.txt', 'initial content');
354+
await createOrAppendFileContent('/test/newfile.txt', 'initial content');
355355

356356
expect(mockFs.writeFile).toHaveBeenCalledWith(
357357
'/test/newfile.txt',
@@ -363,7 +363,7 @@ describe('Lib Functions', () => {
363363
it('appends to existing file', async () => {
364364
mockFs.appendFile.mockResolvedValue(undefined);
365365

366-
await writeOrUpdateFileContent('/test/file.txt', '\nappended content');
366+
await createOrAppendFileContent('/test/file.txt', '\nappended content');
367367

368368
expect(mockFs.appendFile).toHaveBeenCalledWith(
369369
'/test/file.txt',
@@ -385,7 +385,7 @@ describe('Lib Functions', () => {
385385
.mockResolvedValueOnce(undefined);
386386
mockFs.rename.mockResolvedValue(undefined);
387387

388-
await writeOrUpdateFileContent('/test/file.txt', 'content');
388+
await createOrAppendFileContent('/test/file.txt', 'content');
389389

390390
expect(mockFs.writeFile).toHaveBeenCalledTimes(2);
391391
expect(mockFs.rename).toHaveBeenCalled();
@@ -396,7 +396,7 @@ describe('Lib Functions', () => {
396396
(error as any).code = 'EACCES';
397397
mockFs.appendFile.mockRejectedValue(error);
398398

399-
await expect(writeOrUpdateFileContent('/test/file.txt', 'content'))
399+
await expect(createOrAppendFileContent('/test/file.txt', 'content'))
400400
.rejects.toThrow('Permission denied');
401401
});
402402
});

src/filesystem/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
readFileContent,
2323
writeFileContent,
2424
appendFileContent,
25-
writeOrUpdateFileContent,
25+
createOrAppendFileContent,
2626
searchFilesWithValidation,
2727
applyFileEdits,
2828
tailFile,
@@ -118,7 +118,7 @@ const PathContentArgsSchema = z.object({
118118
});
119119
const WriteFileArgsSchema = PathContentArgsSchema;
120120
const AppendFileArgsSchema = PathContentArgsSchema;
121-
const WriteOrUpdateFileArgsSchema = PathContentArgsSchema;
121+
const CreateOrAppendFileArgsSchema = PathContentArgsSchema;
122122

123123
const EditOperation = z.object({
124124
oldText: z.string().describe('Text to search for - must match exactly'),
@@ -374,7 +374,7 @@ server.registerTool(
374374
description:
375375
"Append content to the end of an existing file. This operation adds new content " +
376376
"to the file without modifying existing content. The file must already exist - " +
377-
"use write_file to create new files or write_or_update_file to create or append. " +
377+
"use write_file to create new files or create_or_append_file to create or append. " +
378378
"Only works within allowed directories.",
379379
inputSchema: {
380380
path: z.string(),
@@ -395,9 +395,9 @@ server.registerTool(
395395
);
396396

397397
server.registerTool(
398-
"write_or_update_file",
398+
"create_or_append_file",
399399
{
400-
title: "Write or Update File",
400+
title: "Create or Append File",
401401
description:
402402
"Create a new file with content, or append to an existing file. If the file " +
403403
"does not exist, it will be created with the provided content. If the file " +
@@ -411,10 +411,10 @@ server.registerTool(
411411
outputSchema: { content: z.string() },
412412
annotations: { readOnlyHint: false, idempotentHint: false, destructiveHint: false }
413413
},
414-
async (args: z.infer<typeof WriteOrUpdateFileArgsSchema>) => {
414+
async (args: z.infer<typeof CreateOrAppendFileArgsSchema>) => {
415415
const validPath = await validatePath(args.path);
416416
const existed = await fs.access(validPath).then(() => true).catch(() => false);
417-
await writeOrUpdateFileContent(validPath, args.content);
417+
await createOrAppendFileContent(validPath, args.content);
418418

419419
const message = existed
420420
? `Successfully appended content to ${args.path}`

src/filesystem/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export async function appendFileContent(filePath: string, content: string): Prom
195195
}
196196
}
197197

198-
export async function writeOrUpdateFileContent(filePath: string, content: string): Promise<void> {
198+
export async function createOrAppendFileContent(filePath: string, content: string): Promise<void> {
199199
try {
200200
await appendFileContent(filePath, content);
201201
} catch (error) {

0 commit comments

Comments
 (0)