Spaces:
Running
Running
code.tree avisa al cortar (proyectos grandes)
Browse files- js/tools/code.js +11 -5
js/tools/code.js
CHANGED
|
@@ -122,26 +122,32 @@ export async function findByName(basename, limit = 5) {
|
|
| 122 |
}
|
| 123 |
|
| 124 |
// Árbol de texto (para el modelo y el CONTEXTO). Ignora dependencias/binarios.
|
|
|
|
| 125 |
export async function tree({ path = '', depth = 3 } = {}) {
|
| 126 |
if (!projectHandle) throw new Error('No hay proyecto abierto');
|
| 127 |
let root = projectHandle;
|
| 128 |
for (const p of normalize(path)) root = await root.getDirectoryHandle(p);
|
| 129 |
const out = [];
|
| 130 |
-
let count = 0;
|
| 131 |
async function walk(dir, prefix, d) {
|
| 132 |
-
if (d > depth || count >
|
| 133 |
const entries = [];
|
| 134 |
for await (const e of dir.values()) entries.push(e);
|
| 135 |
entries.sort((a, b) => (a.kind !== b.kind) ? (a.kind === 'directory' ? -1 : 1) : a.name.localeCompare(b.name));
|
| 136 |
for (const e of entries) {
|
| 137 |
if (IGNORE.has(e.name)) continue;
|
| 138 |
-
if (++count >
|
| 139 |
out.push(prefix + (e.kind === 'directory' ? '📁 ' : '') + e.name);
|
| 140 |
-
if (e.kind === 'directory') await walk(e, prefix + ' ', d + 1);
|
| 141 |
}
|
| 142 |
}
|
| 143 |
await walk(root, '', 1);
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
|
| 147 |
const PAGE_SIZE = 100, PAGE_MAX = 500;
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
// Árbol de texto (para el modelo y el CONTEXTO). Ignora dependencias/binarios.
|
| 125 |
+
const TREE_MAX = 800;
|
| 126 |
export async function tree({ path = '', depth = 3 } = {}) {
|
| 127 |
if (!projectHandle) throw new Error('No hay proyecto abierto');
|
| 128 |
let root = projectHandle;
|
| 129 |
for (const p of normalize(path)) root = await root.getDirectoryHandle(p);
|
| 130 |
const out = [];
|
| 131 |
+
let count = 0, truncated = false;
|
| 132 |
async function walk(dir, prefix, d) {
|
| 133 |
+
if (d > depth || count >= TREE_MAX) return;
|
| 134 |
const entries = [];
|
| 135 |
for await (const e of dir.values()) entries.push(e);
|
| 136 |
entries.sort((a, b) => (a.kind !== b.kind) ? (a.kind === 'directory' ? -1 : 1) : a.name.localeCompare(b.name));
|
| 137 |
for (const e of entries) {
|
| 138 |
if (IGNORE.has(e.name)) continue;
|
| 139 |
+
if (++count > TREE_MAX) { truncated = true; return; }
|
| 140 |
out.push(prefix + (e.kind === 'directory' ? '📁 ' : '') + e.name);
|
| 141 |
+
if (e.kind === 'directory') { await walk(e, prefix + ' ', d + 1); if (truncated) return; }
|
| 142 |
}
|
| 143 |
}
|
| 144 |
await walk(root, '', 1);
|
| 145 |
+
let res = out.join('\n') || '(vacío)';
|
| 146 |
+
// Corte con AVISO y guía (como read/search): un «…» pelado se lee como «esto
|
| 147 |
+
// es todo» y el modelo trabaja sobre un árbol incompleto sin saberlo.
|
| 148 |
+
if (truncated)
|
| 149 |
+
res += `\n… árbol recortado (>${TREE_MAX} entradas). Acota con code.tree({path:"subcarpeta"}) o localiza con code.search.`;
|
| 150 |
+
return res;
|
| 151 |
}
|
| 152 |
|
| 153 |
const PAGE_SIZE = 100, PAGE_MAX = 500;
|