Elffuss BraidHub

utopia-ia/elffuss-code public

main · 2.4 KiBRawPermalink
1// Glue específico de Elffuss Code para la Mente genérica (mind.js, core): le
2// da su ciudad de fondo real (motor VibeCodeViewer sobre el proyecto abierto)
3// y la semilla de pensamientos ya guardados en la carpeta-alma del cerebro.
4import * as THREE from 'three';
5import * as codeTools from './tools/code.js';
6import * as ceo from './ceo.js';
7import { buildModel } from './vcc/model.js';
8import { buildCity } from './vcc/builder.js';
9import { THEME as VCC_THEME } from './vcc/theme.js';
10
11const CITY_MAX_FILES = 2600;
12const IGNORE = new Set(['node_modules', '.git', 'dist', 'build', 'target', '__pycache__', '.next', 'venv', '.venv', '.DS_Store']);
13
14async function scanForCity(dir, budget) {
15 const dirs = [], files = [];
16 for await (const e of dir.values()) { if (IGNORE.has(e.name)) continue; (e.kind === 'directory' ? dirs : files).push(e); }
17 dirs.sort((a, b) => a.name.localeCompare(b.name)); files.sort((a, b) => a.name.localeCompare(b.name));
18 const outFiles = [];
19 for (const f of files) { if (budget.n >= CITY_MAX_FILES) break; let size = 0; try { size = (await f.getFile()).size; } catch { /* */ } outFiles.push([f.name, size]); budget.n++; }
20 const outDirs = [];
21 for (const d of dirs) { if (budget.n >= CITY_MAX_FILES) break; outDirs.push(await scanForCity(d, budget)); }
22 return [dir.name, outDirs, outFiles];
23}
24
25export async function buildCityAdapter(scene) {
26 const root = codeTools.handle();
27 if (!root) return null;
28 const tree = await scanForCity(root, { n: 0 });
29 const model = buildModel(tree, null);
30 if (!model.files.length) return null;
31 const extent = Math.max(model.city.box.sx, model.city.box.sz, 1);
32 const scale = Math.min(1, Math.max(0.05, 170 / extent));
33 const cityWrap = new THREE.Group();
34 cityWrap.position.set(0, -95, 0);
35 cityWrap.scale.setScalar(scale);
36 scene.add(cityWrap);
37 const cityCity = buildCity(cityWrap, model, VCC_THEME);
38 return { cityWrap, cityCity, cityModel: model };
39}
40
41export async function loadThoughtsAdapter() {
42 const soul = ceo.getSoulDir();
43 let dir = codeTools.handle();
44 for (const seg of soul.split('/').filter(Boolean)) dir = await dir.getDirectoryHandle(seg);
45 const files = [];
46 for await (const e of dir.values()) if (e.kind === 'file' && e.name.endsWith('.md')) files.push(e);
47 files.sort((a, b) => a.name.localeCompare(b.name));
48 const out = [];
49 for (const f of files.slice(-24)) out.push({ path: soul + '/' + f.name, md: await (await f.getFile()).text() });
50 return out;
51}