upd
This commit is contained in:
34
src/tools/mkdir.js
Normal file
34
src/tools/mkdir.js
Normal 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 };
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user