This commit is contained in:
seb
2026-09-22 18:53:38 +02:00
parent dd197d8b0f
commit 09365539e5
12 changed files with 763 additions and 0 deletions

34
src/tools/mkdir.js Normal file
View File

@@ -0,0 +1,34 @@
'use strict';
import fs from 'fs';
import { defineTool, ToolError } from 'llmorbiter';
import { resolveSafe } from '../sandbox.js';
import { pushUndo } from '../undo.js';
export const mkdirTool = defineTool({
name: 'mkdir',
description: 'Create a directory in the workspace (automatically recursive if parent directories do not exist).',
parameters: {
type: 'object',
additionalProperties: false,
required: ['dirname'],
properties: {
dirname: {
type: 'string',
description: 'Directory path relative to workspace root.',
},
},
},
invoke: async ({ dirname }) => {
const absDir = resolveSafe(dirname);
if (fs.existsSync(absDir)) {
if (!fs.statSync(absDir).isDirectory()) {
throw new ToolError(`Path "${dirname}" already exists and is not a directory.`);
}
return { message: `Directory already exists: "${dirname}"`, created: false };
}
fs.mkdirSync(absDir, { recursive: true });
pushUndo({ op: 'DELETE_DIR', path: dirname });
return { message: `Directory created: "${dirname}"`, created: true };
},
});