fix+feat(projects): Spinner-Bug, Back-Button, kollabierbare Chat-Bloecke, File-Filter

Drei Stefan-Bugs aus dem ersten Deploy-Test plus die fehlenden Polish-
Features fuer die Projekt-Funktion.

Fixes:
- ProjectsBrowser-Spinner-Hang: useRef-Pattern statt useCallback([onActive
  Changed]) — Parent uebergibt inline-arrow-Callbacks, neue Identitaet
  jedes Render → useCallback recomputes → useEffect refeuert → infinite
  Spinner. Fix: Ref-Bridge fuer Callbacks, useCallback mit empty deps.
- ChatScreen Banner: zusaetzlicher × Hauptchat-Button rechts (sichtbar
  nur wenn Projekt aktiv) — ein Tap und zurueck zum Hauptthread, ohne
  Modal-Umweg.

Features:
- Brain ChatOut.project_id: aktive Projekt-ID NACH dem Turn (kann
  durch project_enter/exit-Tools waehrend Turn gewechselt sein). Bridge
  liest sie aus dem /chat-Response und haengt sie an jeden ARIA-Chat-
  Broadcast als payload.projectId.
- App: ChatMessage.projectId-Feld. User-Bubbles werden mit aktiver
  Projekt-ID getaggt vor dem Senden (auch im RVS-Payload). ARIA-Bubbles
  kriegen die ID vom Bridge.
- App: Chat-Verlauf rendert aufeinanderfolgende Project-Messages als
  einklappbaren Block mit Header (▶/▼ + Projekt-Name + Count). Auto-
  Collapse beim Projekt-Wechsel (altes ein, neues aus), Default beim
  ersten Render: alle inaktiven Projekte eingeklappt.
- File-Manager Project-Tagging:
  - diagnostic/server.js: Manifest /shared/config/file_projects.json
    + /api/files-list returnt projectId pro Datei + neuer Endpoint
    /api/files-set-project.
  - bridge/aria_bridge.py: nach App-Upload Auto-Tag mit aktivem Projekt
    (Brain-Status-Query, best-effort fail-silent).
  - App SettingsScreen: scrollbare Projekt-Pill-Reihe als Filter, default
    auf aktives Projekt wenn vorhanden, sonst "Alle Projekte".
  - Diagnostic: zweites Dropdown im Files-Tab, baut Projekt-Optionen
    dynamisch aus /api/brain/projects/list.

Bewusst nicht drin (Folgeschritt):
- Per-File "Projekt zuweisen"-Action (Long-Press / Right-Click)
- Filter-Sync zwischen ChatScreen-Banner und SettingsScreen-Filter

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-13 21:55:02 +02:00
parent 1baa1a7a08
commit 1fb512c2fd
7 changed files with 359 additions and 22 deletions
+38
View File
@@ -1109,6 +1109,11 @@
<option value="aria">Von ARIA (aria_*)</option>
<option value="user">Vom Benutzer</option>
</select>
<select id="files-filter-project" onchange="renderFilesList()" style="background:#080810;color:#E0E0F0;border:1px solid #1E1E2E;padding:6px;border-radius:4px;font-family:inherit;font-size:11px;">
<option value="__all__">Alle Projekte</option>
<option value="">💬 Hauptchat</option>
<!-- Project options werden dynamisch via loadFiles() befuellt -->
</select>
</div>
<div id="files-info" style="margin-top:6px;font-size:10px;color:#8888AA;"></div>
</div>
@@ -4209,6 +4214,37 @@
const d = await r.json();
if (!d.ok) throw new Error(d.error || 'Unbekannter Fehler');
filesCache = d.files || [];
// Projekt-Filter-Optionen aktualisieren — Liste aller bekannten projectIds
// aus den Dateien + Namen via brain api.
const pidsInFiles = new Set(filesCache.map(f => f.projectId).filter(Boolean));
try {
const pr = await fetch('/api/brain/projects/list?include_archived=true');
const pdata = await pr.json();
const projects = pdata?.projects || [];
const sel = document.getElementById('files-filter-project');
if (sel) {
const current = sel.value;
// Bestehende Options ab Index 2 (nach __all__ und Hauptchat) entfernen
while (sel.options.length > 2) sel.remove(2);
for (const p of projects) {
const opt = document.createElement('option');
opt.value = p.id;
opt.textContent = `📁 ${p.name}`;
sel.appendChild(opt);
}
// Auch IDs aus Files die nicht in projects sind (gelöschte Projekte)
const knownIds = new Set(projects.map(p => p.id));
for (const pid of pidsInFiles) {
if (!knownIds.has(pid)) {
const opt = document.createElement('option');
opt.value = pid;
opt.textContent = `📁 ${pid} (gelöscht?)`;
sel.appendChild(opt);
}
}
sel.value = current || '__all__';
}
} catch {}
// Selection bereinigen — nicht mehr existierende Pfade raus
const existing = new Set(filesCache.map(f => f.path));
for (const p of [...filesSelected]) if (!existing.has(p)) filesSelected.delete(p);
@@ -4221,9 +4257,11 @@
function getVisibleFiles() {
const q = (document.getElementById('files-search').value || '').toLowerCase();
const filter = document.getElementById('files-filter').value;
const pidFilter = document.getElementById('files-filter-project')?.value || '__all__';
let files = filesCache.slice();
if (filter === 'aria') files = files.filter(f => f.fromAria);
else if (filter === 'user') files = files.filter(f => !f.fromAria);
if (pidFilter !== '__all__') files = files.filter(f => (f.projectId || '') === pidFilter);
if (q) files = files.filter(f => f.name.toLowerCase().includes(q));
return files;
}
+53
View File
@@ -297,6 +297,32 @@ function writeRuntimeConfig(patch) {
}
// Atomic write: temp-file + rename, laute Logs bei Fehler.
// ── File-Project-Manifest ───────────────────────────────────────────
// Jeder Eintrag map[absoluter_pfad] = project_id (leer = Hauptchat).
// Wird vom files-list-Endpoint + files-set-project gepflegt.
const FILE_PROJECTS_FILE = "/shared/config/file_projects.json";
function loadFileProjects() {
try {
if (!fs.existsSync(FILE_PROJECTS_FILE)) return {};
const data = JSON.parse(fs.readFileSync(FILE_PROJECTS_FILE, "utf-8"));
return (data && typeof data === "object") ? data : {};
} catch {
return {};
}
}
function saveFileProjects(manifest) {
try {
fs.mkdirSync("/shared/config", { recursive: true });
const tmp = FILE_PROJECTS_FILE + ".tmp";
fs.writeFileSync(tmp, JSON.stringify(manifest, null, 2));
fs.renameSync(tmp, FILE_PROJECTS_FILE);
} catch (err) {
log("warn", "files", `file-projects-Manifest schreiben fehlgeschlagen: ${err.message}`);
}
}
function persistActiveSession(key) {
try {
const tmp = SESSION_KEY_FILE + ".tmp";
@@ -1598,6 +1624,7 @@ const server = http.createServer((req, res) => {
const dir = "/shared/uploads";
let entries = [];
try { entries = fs.readdirSync(dir); } catch { entries = []; }
const manifest = loadFileProjects();
const files = entries
.map(name => {
try {
@@ -1610,6 +1637,7 @@ const server = http.createServer((req, res) => {
size: st.size,
mtime: Math.floor(st.mtimeMs),
fromAria: name.startsWith("aria_"),
projectId: manifest[full] || '',
};
} catch { return null; }
})
@@ -1622,6 +1650,31 @@ const server = http.createServer((req, res) => {
res.end(JSON.stringify({ ok: false, error: err.message }));
}
return;
} else if (req.url === "/api/files-set-project" && req.method === "POST") {
// Body: { path, projectId } — projectId leer = Hauptchat (= Eintrag entfernen)
let body = "";
req.on("data", c => { body += c; if (body.length > 8192) req.destroy(); });
req.on("end", () => {
try {
const data = JSON.parse(body || "{}");
const fpath = String(data.path || "");
const pid = String(data.projectId || "");
if (!fpath.startsWith("/shared/uploads/") || !fs.existsSync(fpath)) {
res.writeHead(404, { "Content-Type": "application/json" });
return res.end(JSON.stringify({ ok: false, error: "Datei nicht gefunden" }));
}
const manifest = loadFileProjects();
if (pid) manifest[fpath] = pid;
else delete manifest[fpath];
saveFileProjects(manifest);
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ ok: true, path: fpath, projectId: pid }));
} catch (err) {
res.writeHead(500, { "Content-Type": "application/json" });
res.end(JSON.stringify({ ok: false, error: err.message }));
}
});
return;
} else if ((req.url.startsWith("/api/files-download?") || req.url.startsWith("/api/files-view?")) && req.method === "GET") {
// /api/files-download → mit Content-Disposition:attachment (Browser downloaded)
// /api/files-view → mit Disposition:inline (Browser zeigt PDF/Bilder im Tab)