@saber2pr/ai-agent 0.0.45 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -275,16 +275,24 @@ const getFilesystemTools = (targetDir) => {
|
|
|
275
275
|
});
|
|
276
276
|
const getFileInfoTool = (0, createTool_1.createTool)({
|
|
277
277
|
name: 'get_file_info',
|
|
278
|
-
description: '
|
|
279
|
-
'Only works within allowed directories.',
|
|
278
|
+
description: '查看文件元数据(大小、行数、修改时间)。读取大文件前务必先调用此工具。',
|
|
280
279
|
parameters: GetFileInfoArgsSchema,
|
|
281
280
|
handler: async (args) => {
|
|
282
281
|
const validPath = await (0, lib_1.validatePath)(targetDir, args.path);
|
|
283
|
-
const
|
|
284
|
-
|
|
282
|
+
const stats = await promises_1.default.stat(validPath);
|
|
283
|
+
// 计算行数:读取内容并按换行符分割
|
|
284
|
+
// 注意:对于极大的文件,这种方式可能稍慢,但对普通源代码文件非常有效
|
|
285
|
+
const content = await promises_1.default.readFile(validPath, 'utf-8');
|
|
286
|
+
const lineCount = content.split('\n').length;
|
|
287
|
+
const info = {
|
|
288
|
+
size: `${(stats.size / 1024).toFixed(2)} KB`,
|
|
289
|
+
lineCount: lineCount, // 新增行号字段
|
|
290
|
+
mtime: stats.mtime.toLocaleString(),
|
|
291
|
+
type: path_1.default.extname(validPath) || 'unknown'
|
|
292
|
+
};
|
|
293
|
+
return Object.entries(info)
|
|
285
294
|
.map(([key, value]) => `${key}: ${value}`)
|
|
286
295
|
.join('\n');
|
|
287
|
-
return text;
|
|
288
296
|
},
|
|
289
297
|
});
|
|
290
298
|
const grepSearchTool = (0, createTool_1.createTool)({
|