full initial implementation
This commit is contained in:
1 parent
65fc75e509
commit
d9d9b7f463
15 files changed
+799
-4
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
export const spec = {
|
||||
name: 'list_files',
|
||||
description: 'List every file in the space, as paths relative to the space directory.',
|
||||
parameters: { type: 'object', properties: {} },
|
||||
};
|
||||
|
||||
export default async function (args, ctx) {
|
||||
const files = [];
|
||||
const walk = (dir, prefix) => {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
||||
if (entry.isDirectory()) walk(path.join(dir, entry.name), rel);
|
||||
else files.push(rel);
|
||||
}
|
||||
};
|
||||
walk(ctx.dir, '');
|
||||
return { files };
|
||||
}
|
||||
Reference in new issue
Block a user