From be000985ed61db2553caaf560438669ba9370fe8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 08:31:00 +0000 Subject: [PATCH] =?UTF-8?q?[208]=20Anonymit=C3=A4ts-Tor=20an=20allen=20Exp?= =?UTF-8?q?ort-Einstiegen:=20Berichte,=20Bild-/Rendering-Exporte,=20CLI=20?= =?UTF-8?q?(--ignore-anonymity),=20KI-Export;=20Dateiname=20nach=20Wiederh?= =?UTF-8?q?erstellen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 13 +++-- src/cli/cli.test.ts | 25 ++++++++++ src/cli/main.ts | 32 +++++++++++- src/core/aiToolDefs.ts | 2 +- src/core/aiTools.test.ts | 10 ++++ src/core/aiTools.ts | 13 ++++- src/panels/AreaTableSection.tsx | 15 +++--- src/panels/CostEstimateSection.tsx | 15 +++--- src/panels/ElementScheduleSection.tsx | 15 +++--- src/panels/OpeningScheduleSection.tsx | 15 +++--- src/panels/ProgramCompareSection.tsx | 15 +++--- src/panels/RoomBalancePanel.tsx | 3 +- src/panels/RoomBookSection.tsx | 15 +++--- src/state/aiAccess.ts | 6 ++- src/state/anonymityGate.entries.test.ts | 66 +++++++++++++++++++++++++ src/state/anonymityGate.ts | 7 +++ src/state/panelHost/layoutsHost.ts | 9 ++-- src/state/useProjectFileActions.ts | 4 +- src/ui/CameraTourDialog.tsx | 7 ++- src/ui/ImageExportDialog.tsx | 10 ++-- src/ui/RenderDialog.tsx | 22 ++++++--- 21 files changed, 260 insertions(+), 59 deletions(-) create mode 100644 src/state/anonymityGate.entries.test.ts diff --git a/TODO.md b/TODO.md index bc1bb4fd..2bebcb8d 100644 --- a/TODO.md +++ b/TODO.md @@ -223,9 +223,16 @@ Kennwort, anonym) als PDF; Austausch mit Fachplanern über DXF/IFC. Einzelwort ab 5 Zeichen, allgemeine Wörter („Haus“, „Wohnen“ …) und blosse Zahlen zählen nicht. Dialog `ui/AnonymityDialog.tsx` listet Bereich, Fundstelle, Text, Begriff; „Trotzdem exportieren“ / „Abbrechen“ (Overlay, kein `window.confirm`). Kopfdaten waren schon leer (PDF-Info nur Kennwort, Producer/Datum neutralisiert — auch „Dossier“ bleibt weg, weil Programm + Version + Datum die Herkunft eingrenzen; IFC-Kopf/IfcOwnerHistory, DXF-Kopf, STEP): - keine Lücke gefunden. Tests: Rust `competition` (Treffer je Textort, Fehlalarme, Umlaute), vitest `competitionCheck`, e2e `competition`. Offen: Berichte-PDF - (Flächen, Raumbuch …) und Bild-/Rendering-Exporte laufen nicht durch das Tor; Prüfung läuft nur im Dialog-Weg (CLI/KI-Werkzeuge nicht); der - Dateiname der Ausgabe wird nur beim Direkt-Export geprüft; nicht in der Tauri-App/auf dem Mac geprüft. + keine Lücke gefunden. Tests: Rust `competition` (Treffer je Textort, Fehlalarme, Umlaute), vitest `competitionCheck`, e2e `competition`. **Nachtrag (14.11., spät)**: das Tor + hängt jetzt an allen Export-Einstiegen der Oberfläche: Berichte (Fläche, Raumbuch, Kosten, Öffnungen, Bauteile, Programm, Flächenbilanz) als CSV und PDF, + 3D-Bild-PNG, Rendering (PNG, .blend, Blender-Paket), Kamerafahrt-Video, Layout-Ordner-PDF, KI-Werkzeug-Speichern; `runWithAnonymityGate` für + Knopf-Handler, Dateiname der Ausgabe wird mitgeprüft. Bild-/Video-/Rendering-Dateinamen nutzen jetzt den Kennwort-Namen (`exportProjectName`) + statt `project.name`. Vitest `state/anonymityGate.entries.test.ts` gleicht ab: jede Oberflächen-Datei mit Datei-Ausgabe ruft das Tor auf + (neue Einstiege fallen dort auf). CLI: bei anonymer Abgabe prüfen plan/section/elevation/dxf/dwg/ifc/obj/stl/glb/gltf/step/schedule/kennzahlen/ + raumprogramm/render/blend/model3d den Freitext, Treffer auf stderr, Exit-Code 3, `--ignore-anonymity` übergeht (Test in `cli.test.ts`); + KI-/MCP-Werkzeug `export` ohne `save` liefert bei Treffern nichts aus (Argument `ignoreAnonymity`). Der Projekt-Dateiname ist auch nach + Autosave-Wiederherstellen und Browser-/Electron-Start-Öffnen Suchbegriff, beim „Neu“ wird er gelöscht. Offen: `dossier-cli convert` prüft nicht; + BCF-Export bewusst ohne Tor; nicht in der Tauri-App/auf dem Mac geprüft (Dialog-Weg nur per Code-Abgleich, kein e2e für die neuen Knöpfe). - [61] Raumprogramm gegen Modell und Flächennachweis SIA 416 als Tabelle/Layout-Element ([70]); Kennzahlen (GF, GV, HNF/GF, Fassadenanteil). - 3D-Bilder für die Abgabe: hochaufgelöster PNG-Export (Perspektive, Axonometrie, Schatten), Sonnenstand; [205] Pausfolie. - [199]/[204] Plan- und App-Review-Reste im Darstellungsbereich 1:500/1:200 schliessen. diff --git a/src/cli/cli.test.ts b/src/cli/cli.test.ts index b40abd05..062fe3a1 100644 --- a/src/cli/cli.test.ts +++ b/src/cli/cli.test.ts @@ -52,6 +52,31 @@ describe("dossier-cli", () => { expect(await run([broken, "plan", "--out", join(dir, "haengend.svg")])).toBe(0); }); + it("anonyme Abgabe: Export prüft den Freitext, Treffer brechen ab, --ignore-anonymity übergeht ([208])", async () => { + const anon = join(dir, "seeblick-meierhofer.obp"); + const p = { + ...sampleProject, + name: "Seeblick Meierhofer", + competition: { anonymous: true, keyword: "FALKE 7", identifiers: "" }, + rooms: [{ ...sampleProject.rooms![0], name: "Büro Seeblick Meierhofer" }, ...sampleProject.rooms!.slice(1)], + }; + writeFileSync(anon, serializeProject(p as typeof sampleProject)); + const err = vi.spyOn(process.stderr, "write").mockImplementation(() => true); + try { + const target = join(dir, "anon.svg"); + expect(await run([anon, "plan", "--out", target])).toBe(3); + expect(existsSync(target)).toBe(false); + expect(err.mock.calls.map((c) => String(c[0])).join("")).toContain("Anonyme Abgabe"); + expect(await run([anon, "info"])).toBe(0); // kein Export + expect(await run([anon, "plan", "--out", target, "--ignore-anonymity"])).toBe(0); + expect(existsSync(target)).toBe(true); + } finally { + err.mockRestore(); + } + // Nicht anonym: keine Prüfung. + expect(await run([file, "plan", "--out", join(dir, "nicht-anon.svg")])).toBe(0); + }); + it("Plan als SVG", async () => { const out = join(dir, "eg.svg"); expect(await call("plan", "--out", out)).toBe(0); diff --git a/src/cli/main.ts b/src/cli/main.ts index 0882c6f5..91e7b95e 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -101,6 +101,8 @@ import { areaReportToSvg, buildAreaReportPdf, exportProjectName, + isAnonymous, + anonymityFindings, sunPosition, shadowPolygons, projectLatLon, @@ -476,7 +478,8 @@ export async function run(argv: string[]): Promise { " dossier-cli pointcloud-info [--voxel 0.05] [--max 2000000]\n" + " dossier-cli bcf-info \n" + " dossier-cli pdf-info [--page 1]\n" + - " dossier-cli mcp --app [--port 7979] [--token schlüssel] (MCP-Brücke zur offenen App)\n", + " dossier-cli mcp --app [--port 7979] [--token schlüssel] (MCP-Brücke zur offenen App)\n" + + " Anonyme Wettbewerbs-Abgabe: Exporte prüfen den Freitext (Exit 3 bei Treffern); --ignore-anonymity übergeht die Prüfung\n", ); return 2; } @@ -903,9 +906,36 @@ async function importSyntheticContext(base: Project, args: Args, rows: Array<[st return cur; } +/** Befehle, die eine Ausgabe-Datei erzeugen (für die Anonymitäts-Prüfung einer Wettbewerbs-Abgabe, [208]). */ +const EXPORT_COMMANDS = new Set(["plan", "section", "elevation", "dxf", "dwg", "ifc", "obj", "stl", "glb", "gltf", "step", "stp", "schedule", "kennzahlen", "raumprogramm", "render", "blend", "model3d"]); + +/** + * [208] Anonyme Abgabe: vor einem Export den Freitext prüfen. Treffer stehen auf stderr; ohne `--ignore-anonymity` + * bricht der Befehl mit Exit-Code 3 ab. Gibt den Exit-Code zurück, `0` = weiter. + */ +function anonymityGate(project: Project, file: string, command: string, args: Args): number { + if (!EXPORT_COMMANDS.has(command) || !isAnonymous(project)) return 0; + const texts = [] as { area: string; place: string; text: string }[]; + const target = args.flags.get("out"); + if (target && target !== "-" && target !== "true") texts.push({ area: "export", place: "fileName", text: basename(target) }); + const findings = anonymityFindings(project, { fileName: file.startsWith(":") ? "" : basename(file), texts }); + if (findings.length === 0) return 0; + const lines = findings.map((f) => ` ${f.area} / ${f.place}: „${f.text}" enthält „${f.term}" (${f.kind})`); + const ignore = args.flags.has("ignore-anonymity") && args.flags.get("ignore-anonymity") !== "false"; + process.stderr.write(`Anonyme Abgabe: ${findings.length} Treffer im Freitext:\n${lines.join("\n")}\n`); + if (ignore) { + process.stderr.write("Hinweis: --ignore-anonymity gesetzt, Export läuft trotzdem.\n"); + return 0; + } + process.stderr.write("Export abgebrochen (zum Übergehen: --ignore-anonymity).\n"); + return 3; +} + /** Führt EINEN Befehl gegen ein geladenes Projekt aus (Rückgabe = Exit-Code). */ async function execute(project: Project, file: string, command: string, rest: string[], args: Args): Promise { const scale = Number(args.flags.get("scale") ?? 100); + const blocked = anonymityGate(project, file, command, args); + if (blocked !== 0) return blocked; // [257] `bench --context`: vorher synthetische Kontext-Importe (Kataster, Höhenlinien, Gebäudenetze) ins Projekt laden. const contextRows: Array<[string, number]> = []; if (command === "bench" && args.flags.has("context")) { diff --git a/src/core/aiToolDefs.ts b/src/core/aiToolDefs.ts index 8cd08192..a5c79199 100644 --- a/src/core/aiToolDefs.ts +++ b/src/core/aiToolDefs.ts @@ -81,7 +81,7 @@ export const AI_TOOLS: AiToolDef[] = [ "Exportiert Grundriss als SVG (format=svg) oder PDF (pdf, nur App) bzw. das Modell als IFC (ifc). Liefert den Inhalt " + "(PDF base64); mit save=true öffnet die App den Speichern-Dialog und die Nutzerin wählt den Ort.", inputSchema: obj( - { format: { type: "string", enum: ["svg", "pdf", "ifc"] }, level: { type: "string" }, scale: { type: "number" }, save: { type: "boolean" } }, + { format: { type: "string", enum: ["svg", "pdf", "ifc"] }, level: { type: "string" }, scale: { type: "number" }, save: { type: "boolean" }, ignoreAnonymity: { type: "boolean" } }, ["format"], ), }, diff --git a/src/core/aiTools.test.ts b/src/core/aiTools.test.ts index 25d08247..222039c1 100644 --- a/src/core/aiTools.test.ts +++ b/src/core/aiTools.test.ts @@ -105,6 +105,16 @@ describe("KI-Werkzeuge (gemeinsame Liste)", () => { expect((await callAiTool(host, "export", { format: "svg", save: true })).isError).toBe(true); // Speichern nur mit Dialog expect((await callAiTool(host, "gibtsnicht", {})).isError).toBe(true); }); + it("anonyme Abgabe: Export mit Freitext-Treffern wird nicht ausgeliefert, ignoreAnonymity übergeht ([208])", async () => { + const { host } = fakeHost(false); + const real = host.project(); + const anon = { ...real, name: "Seeblick Meierhofer", competition: { anonymous: true, keyword: "FALKE 7", identifiers: "" }, rooms: [{ ...real.rooms![0], name: "Büro Seeblick Meierhofer" }, ...real.rooms!.slice(1)] } as Project; + const h: AiHost = { ...host, project: () => anon }; + const blocked = await callAiTool(h, "export", { format: "svg" }); + expect(blocked.isError).toBe(true); + expect(textOf(blocked)).toContain("Anonyme Abgabe"); + expect(textOf(await callAiTool(h, "export", { format: "svg", ignoreAnonymity: true }))).toContain(" { diff --git a/src/core/aiTools.ts b/src/core/aiTools.ts index 125b24ca..0b3269c6 100644 --- a/src/core/aiTools.ts +++ b/src/core/aiTools.ts @@ -17,6 +17,8 @@ import { computeKennzahlen, checkRoomProgram } from "../analysis/kennzahlen"; import { computeAreaTable, computeIvhb } from "../analysis/areaTable"; import { checkSiteRules } from "../analysis/siteRules"; import { loadFileio } from "../engine/fileioWasm"; +import { anonymityFindings } from "../export/competitionCheck"; +import { exportProjectName } from "../export/competitionIdentity"; import { documentFor } from "./document"; import { validateProject, projectWarnings, type CoreOp } from "./ops"; import { aiText, aiToolDef, randomHex, type AiToolResult } from "./aiToolDefs"; @@ -174,7 +176,7 @@ const appOnly = (name: string) => err(`${name}: nur mit der laufenden App (dossi async function exportTool(host: AiHost, project: Project, args: Record): Promise { const format = String(args.format); - const stem = project.name || "projekt"; + const stem = exportProjectName(project) || "projekt"; const scale = Number(args.scale ?? 100); if (args.save === true && !host.save) return err("save: Speichern nur in der App (Dialog, Ort wählt die Nutzerin)"); let data: string | Uint8Array; @@ -199,6 +201,15 @@ async function exportTool(host: AiHost, project: Project, args: Record 0) { + const lines = found.slice(0, 20).map((f) => `${f.area} / ${f.place}: „${f.text}" enthält „${f.term}"`); + return err(`Anonyme Abgabe: ${found.length} Treffer im Freitext, Export nicht ausgeliefert (mit ignoreAnonymity=true übergehen):\n${lines.join("\n")}`); + } + } if (args.save === true) { const ok = await host.save!(data, file, mime); return ok ? aiText(`gespeichert: ${file}`) : err("Speichern abgebrochen"); diff --git a/src/panels/AreaTableSection.tsx b/src/panels/AreaTableSection.tsx index 4c14aad2..d03ab043 100644 --- a/src/panels/AreaTableSection.tsx +++ b/src/panels/AreaTableSection.tsx @@ -12,6 +12,7 @@ import { exportProjectName, areaReportToCsv, buildAreaReport, buildAreaReportPdf import type { AgfBasis } from "../core"; import { DEFAULT_AREA_INPUTS, ivhbOptionsOf, type AreaInputs } from "./areaInputs"; import { downloadCsv } from "./downloadFile"; +import { runWithAnonymityGate } from "../state/anonymityGate"; import { useStore } from "../state/appStore"; const BASES: AgfBasis[] = ["ngf", "gf", "nf"]; @@ -29,11 +30,13 @@ export function AreaTableSection() { const stem = `${exportProjectName(project) || "projekt"}-flaechen`; const exportPdf = () => { - try { - buildAreaReportPdf(report).save(`${stem}.pdf`); - } catch { - notify(t("areas.exportPdf.fail")); - } + runWithAnonymityGate(project, [`${stem}.pdf`], () => { + try { + buildAreaReportPdf(report).save(`${stem}.pdf`); + } catch { + notify(t("areas.exportPdf.fail")); + } + }); }; return ( @@ -41,7 +44,7 @@ export function AreaTableSection() {
{t("areas.title")} -