Skip to content

armgit / SOMA

Public Imported from GitHub
0

Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice

App: Zwischenergebnisse nicht in Verlauf und ZIP, auch in älteren Projekten (E64)

Kai-Jungsthoefelc52613bc157a
diff --git a/app/src/main/git.ts b/app/src/main/git.ts
index 9584397..eabbece 100644
--- a/app/src/main/git.ts
+++ b/app/src/main/git.ts
@@ -17,11 +17,17 @@ const APP_SUBJECT = /^(Neues Modell angelegt|Automatischer Snapshot beim Speiche
/** Gilt für jeden Aufruf: UTF-8-Pfade lesbar, keine Zeilenenden-Umwandlung (ZIPs wandern zwischen Systemen). */
const COMMON = ['-c', 'core.quotepath=false', '-c', 'core.autocrlf=false'];
/**
- * `output/` zählt nicht als Änderung: STEP-Dateien sind nicht byte-stabil (Zeitstempel, teils Reihenfolge).
- * `.soma/geometry/` (Geometrie für das Messen) ist ein Zwischenergebnis. Ältere Projekte haben es noch nicht in der
- * .gitignore, deshalb klammert die App es selbst aus, beim Status und beim Hinzufügen (siehe addAll).
+ * Zwischenergebnisse der App, die nie in den Verlauf gehören: Geometrie für das Messen, gebaute Animationen, Ergebnisse
+ * von soma analyze (bis zu 70 MB je Auswertung) und Bilder und Videos von soma render. Ältere Projekte haben sie noch
+ * nicht in der .gitignore, deshalb klammert die App sie selbst aus, beim Status und beim Hinzufügen (siehe addAll), und
+ * trägt sie beim Öffnen in .git/info/exclude ein, damit auch die Commits des Agenten sie nicht aufnehmen (ensureIgnored).
*/
-const NOT_OUTPUT = ['--', '.', ':(exclude)output', ':(exclude).soma/geometry'];
+const APP_CACHES = ['.soma/geometry', '.soma/anim', '.soma/results', 'renders'];
+/** `output/` zählt nicht als Änderung: STEP-Dateien sind nicht byte-stabil (Zeitstempel, teils Reihenfolge). */
+const NOT_OUTPUT = ['--', '.', ':(exclude)output', ...APP_CACHES.map((p) => `:(exclude)${p}`)];
+/** Was die Vorlage in der .gitignore hat (resources/template/.gitignore), für ältere Projekte in .git/info/exclude. */
+const APP_IGNORES = ['.soma/model.glb', '.soma/model.map.json', '.soma/build.json', '.soma/zip-info.json', '.soma/feedback/',
+ ...APP_CACHES.map((p) => `${p}/`)];
const HASH = /^[0-9a-f]{7,40}$/;
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
@@ -52,12 +58,31 @@ export class GitRepo {
}
/**
- * Alles vormerken außer `.soma/geometry/`. Ein Ausschluss im Pfad (`:(exclude)…`) ginge nicht: Steht der Ordner in
- * der .gitignore (neue Projekte), bricht `git add` dann mit Fehler ab. Deshalb danach aus dem Index nehmen, was dort liegt.
+ * Alles vormerken außer den Zwischenergebnissen (APP_CACHES). Ein Ausschluss im Pfad (`:(exclude)…`) ginge nicht: Steht
+ * der Ordner in der .gitignore (neue Projekte), bricht `git add` dann mit Fehler ab. Deshalb danach aus dem Index nehmen,
+ * was dort liegt. Hat ein älteres Projekt sie schon im Verlauf, nimmt der nächste Snapshot sie heraus (die Dateien bleiben).
*/
private async addAll(): Promise<void> {
await this.mustRun(['add', '-A'], true);
- await this.mustRun(['rm', '-r', '--cached', '--ignore-unmatch', '-q', '--', '.soma/geometry'], true);
+ await this.mustRun(['rm', '-r', '--cached', '--ignore-unmatch', '-q', '--', ...APP_CACHES], true);
+ }
+
+ /**
+ * Trägt die Zwischenergebnisse in .git/info/exclude ein, soweit sie dort fehlen. Gilt auch für `git add -A` des Agenten
+ * und ändert keine Datei des Projekts (die .gitignore gehört dem Nutzer). Nur eine Erleichterung: Fehler stören nichts.
+ */
+ async ensureIgnored(): Promise<void> {
+ try {
+ if (!(await this.isRepo())) return;
+ const file = path.join(this.dir, '.git', 'info', 'exclude');
+ const have = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
+ const lines = new Set(have.split(/\r?\n/).map((l) => l.trim()));
+ const missing = APP_IGNORES.filter((p) => !lines.has(p));
+ if (!missing.length) return;
+ fs.mkdirSync(path.dirname(file), { recursive: true });
+ const head = have && !have.endsWith('\n') ? '\n' : '';
+ fs.appendFileSync(file, `${head}# SOMA: Zwischenergebnisse der App (neue Projekte haben sie in der .gitignore)\n${missing.join('\n')}\n`);
+ } catch { /* nächster Versuch beim nächsten Öffnen */ }
}
private async mustRun(args: string[], write = false): Promise<string> {
diff --git a/app/src/main/projects.ts b/app/src/main/projects.ts
index 2adc3fd..9964ffd 100644
--- a/app/src/main/projects.ts
+++ b/app/src/main/projects.ts
@@ -86,6 +86,7 @@ export class ProjectController {
const builds = new BuildManager(dir);
const terminals = new TerminalManager(this.wc, dir);
const git = new GitRepo(dir);
+ void git.ensureIgnored(); // ältere Projekte: Zwischenergebnisse auch aus den Commits des Agenten heraushalten
builds.on('status', (st) => this.send('build:status', st));
const anims = new AnimBuilder(dir, () => this.send('anim:changed'));
const stopWatch = watchProject(dir, (rel) => builds.sourceChanged(rel ? path.join(dir, rel) : null), () => this.send('fs:changed'),
diff --git a/app/src/main/zip.ts b/app/src/main/zip.ts
index 820a485..a3b4df9 100644
--- a/app/src/main/zip.ts
+++ b/app/src/main/zip.ts
@@ -11,8 +11,13 @@ export const ZIP_INFO_PATH = '.soma/zip-info.json';
/** Wird nie gepackt: Umgebungen und Caches (Umgebung wird aus requirements.txt neu gebaut, Cache neu erzeugt). */
const SKIP_DIRS = new Set(['.venv', 'venv', 'env', '__pycache__', 'node_modules']);
const SKIP_FILES = new Set(['.soma/model.glb', '.soma/model.map.json', '.soma/build.json']);
-/** Ganze Ordner, die nie gepackt werden (Pfad relativ zum Projekt): die Geometrie für das Messen entsteht beim Bauen neu. */
-const SKIP_PATHS = new Set(['.soma/geometry']);
+/**
+ * Ganze Ordner, die nie gepackt werden (Pfad relativ zum Projekt): die Geometrie für das Messen entsteht beim Bauen neu,
+ * Animationen baut die App beim Öffnen neu, Ergebnisse von soma analyze (bis zu 70 MB je Auswertung) rechnet man neu.
+ */
+const SKIP_PATHS = new Set(['.soma/geometry', '.soma/anim', '.soma/results']);
+/** Schon gepackt (Git-Objekte sind zlib, Bilder und Videos komprimiert): nur ablegen, nochmal Deflate kostet nur Zeit. */
+const STORED = /^\.git\/objects\/|\.(png|jpe?g|webp|mp4|webm|zip|gz|7z|pack)$/i;
const MAX_UNPACKED = 2 * 1024 ** 3;
function collect(root: string): string[] {
@@ -34,7 +39,7 @@ function collect(root: string): string[] {
export async function saveProjectZip(dir: string, zipPath: string, info: ZipInfo): Promise<{ files: number; bytes: number }> {
const files = collect(dir);
const zip = new yazl.ZipFile();
- for (const rel of files) if (rel !== ZIP_INFO_PATH) zip.addFile(path.join(dir, rel), rel);
+ for (const rel of files) if (rel !== ZIP_INFO_PATH) zip.addFile(path.join(dir, rel), rel, { compress: !STORED.test(rel) });
zip.addBuffer(Buffer.from(JSON.stringify(info, null, 2)), ZIP_INFO_PATH);
zip.end();
const tmp = zipPath + '.part';
diff --git a/app/test/unit.mjs b/app/test/unit.mjs
index e3c6486..f37dc88 100644
--- a/app/test/unit.mjs
+++ b/app/test/unit.mjs
@@ -222,6 +222,48 @@ try {
check('animations/*.py: Animation, kein Model-Build. model.py, parts/, inputs/ bauen das Modell', affectsAnimation('animations/deckel.py') && affectsAnimation('animations\\x.py')
&& !affectsBuild('animations/deckel.py') && affectsBuild('model.py') && affectsBuild('parts/lid.py') && affectsBuild('inputs/a.step')
&& !affectsAnimation('animations/sub/x.py') && !affectsAnimation('model.py') && !affectsAnimation('animations/notes.md'));
+
+ // Zwischenergebnisse der App (Ergebnisse von soma analyze bis 70 MB) nicht in Snapshot und ZIP, auch in älteren
+ // Projekten ohne die Einträge in der .gitignore. dugite (und die CommonJS-Pakete für ZIP) bleiben extern, das Bündel
+ // liegt deshalb in app/ (dort findet Node node_modules).
+ const gz = path.join(APP, 'test', `.unit-gitzip-${process.pid}.mjs`);
+ await build({ stdin: { contents: "export { GitRepo } from './src/main/git.ts'; export { saveProjectZip, readZipTexts } from './src/main/zip.ts';", resolveDir: APP, loader: 'ts' },
+ outfile: gz, bundle: true, platform: 'node', format: 'esm', external: ['dugite', 'yazl', 'yauzl'], logLevel: 'silent' });
+ try {
+ const { GitRepo, saveProjectZip, readZipTexts } = await import(pathToFileURL(gz).href);
+ const old = path.join(tmp, 'altprojekt');
+ const put = (rel, text) => { fs.mkdirSync(path.dirname(path.join(old, rel)), { recursive: true }); fs.writeFileSync(path.join(old, rel), text); };
+ put('model.py', 'x = 1\n');
+ put('.gitignore', '__pycache__/\n'); // Stand vor E58
+ const repo = new GitRepo(old);
+ await repo.init('Neues Modell angelegt');
+ // So hat es der Agent in älteren Projekten mit `git add -A` committet
+ put('.soma/results/thickness.glb', 'GROSS');
+ put('renders/ansicht-iso.png', 'PNG');
+ await repo.run(['add', '-A'], true);
+ await repo.run(['commit', '-q', '-m', 'Agent'], true);
+ await repo.ensureIgnored();
+ await repo.ensureIgnored();
+ const excl = fs.readFileSync(path.join(old, '.git', 'info', 'exclude'), 'utf8');
+ check('Ältere Projekte: .git/info/exclude nennt .soma/results/, .soma/anim/ und renders/ (einmal), die .gitignore bleibt',
+ excl.split('\n').filter((l) => l === '.soma/results/').length === 1 && excl.includes('.soma/anim/') && excl.includes('renders/')
+ && fs.readFileSync(path.join(old, '.gitignore'), 'utf8') === '__pycache__/\n', excl.slice(-160));
+ put('.soma/results/thickness.glb', 'NEU UND GROSS');
+ put('.soma/anim/deckel.glb', 'ANIM');
+ check('Neues Ergebnis zählt nicht als ungespeicherte Änderung', !(await repo.status()).dirty);
+ put('model.py', 'x = 2\n');
+ await repo.snapshot('Automatischer Snapshot beim Speichern');
+ const tracked = (await repo.run(['ls-files'])).out;
+ check('Snapshot nimmt Ergebnis und Bilder aus dem Verlauf, die Dateien bleiben', tracked.includes('model.py') && !tracked.includes('.soma/results')
+ && !tracked.includes('renders/') && fs.existsSync(path.join(old, '.soma', 'results', 'thickness.glb')), tracked);
+ const zip = path.join(tmp, 'altprojekt.zip');
+ await saveProjectZip(old, zip, { savedAt: '', head: null, id: 'x', name: 'x' });
+ const inZip = await readZipTexts(zip, ['model.py', '.soma/results/thickness.glb', '.soma/anim/deckel.glb', 'renders/ansicht-iso.png']);
+ check('ZIP: ohne .soma/results und .soma/anim, mit Bildern und Modell', inZip['model.py'] === 'x = 2\n' && inZip['.soma/results/thickness.glb'] === null
+ && inZip['.soma/anim/deckel.glb'] === null && inZip['renders/ansicht-iso.png'] === 'PNG', JSON.stringify(inZip));
+ } finally {
+ fs.rmSync(gz, { force: true });
+ }
} catch (e) {
console.log('ABBRUCH:', e.message);
t.fail();