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: kleinere ZIP, renders/ bleibt draussen, Git-Verlauf wird vor dem Speichern gepackt (E75)

Kai-Jungsthoefelfc35fb016fbd
diff --git a/app/resources/template/AGENTS.md b/app/resources/template/AGENTS.md
index 181d358..84a7be6 100644
--- a/app/resources/template/AGENTS.md
+++ b/app/resources/template/AGENTS.md
@@ -16,7 +16,7 @@ The app shows the result in a 3D viewer next to this terminal. Notes and wishes
| `exports/` | Single-part exports written by `soma export` |
| `animations/` | Optional. Motion, camera flights and captions in Python (`soma.anim`), one file per topic. The skill for animation explains them |
| `analyses/` | Optional. Load cases for `soma analyze fem` in Python (`soma.fem`), one file per load case. The skill for FEM explains them |
-| `renders/` | Pictures and videos written by `soma render`. Not in the version history |
+| `renders/` | Pictures and videos written by `soma render`. Not in the version history and not in the saved ZIP |
| `.soma/` | App data (viewer cache, build status, feedback images, skills, built animations, analysis results). Do not edit. Read the skills in `.soma/skills/` as the list at the end of this file says, and files in `.soma/feedback/` when the user points you to them |
## Rules for model.py
diff --git a/app/src/main/git.ts b/app/src/main/git.ts
index 02eb182..3764388 100644
--- a/app/src/main/git.ts
+++ b/app/src/main/git.ts
@@ -141,6 +141,21 @@ export class GitRepo {
});
}
+ /**
+ * Packt die Objekte vor dem Speichern als ZIP (E75). Lose legt Git jede Fassung von output/model.step ganz ab, nur mit
+ * zlib komprimiert, gepackt ähnliche Fassungen als Unterschied (Motor: 35 statt 81 MB). Commits und Hashes bleiben, wie
+ * sie sind (E35). `--keep-unreachable`: Nichts wird gelöscht, auch nicht Unerreichbares (etwa Blobs, die addAll wieder
+ * aus dem Index nimmt, oder Reste nach `git gc` des Agenten), es kommt mit ins Pack. Sonst blieben solche Objekte lose
+ * liegen, und jedes Speichern packte neu. `-n`: keine Dateien für Git-Server. Liefert false, wenn nichts lose lag.
+ */
+ async pack(): Promise<boolean> {
+ return this.serial(async () => {
+ if (/^count: 0$/m.test(await this.mustRun(['count-objects', '-v']))) return false;
+ await this.mustRun(['repack', '-a', '-d', '--keep-unreachable', '-n', '-q'], true);
+ return true;
+ });
+ }
+
/** Verlauf, älteste zuerst. Ein kaputtes oder leeres Repository liefert eine leere Liste. */
async log(limit = 500): Promise<Commit[]> {
const fmt = '--format=%H%x1f%h%x1f%an%x1f%aI%x1f%s%x1f%(trailers:key=Created-by,key=Erstellt-von,valueonly,separator=%x2c)%x1e';
diff --git a/app/src/main/projects.ts b/app/src/main/projects.ts
index 1242886..56aa7a2 100644
--- a/app/src/main/projects.ts
+++ b/app/src/main/projects.ts
@@ -297,6 +297,9 @@ export class ProjectController {
if (await s.git.isRepo()) {
try { snapshot = await s.git.snapshot('Automatic snapshot on save'); }
catch (e) { warnings.push(`Could not add a snapshot to the history: ${e instanceof Error ? e.message : String(e)}`); }
+ // Ähnliche Fassungen (vor allem output/model.step) als Unterschied ablegen, das macht die ZIP deutlich kleiner (E75)
+ try { await s.git.pack(); }
+ catch (e) { warnings.push(`Git could not pack the history, the ZIP is larger than necessary: ${e instanceof Error ? e.message : String(e)}`); }
} else warnings.push('No Git history: no snapshot was created.');
const head = await s.git.head();
diff --git a/app/src/main/zip.ts b/app/src/main/zip.ts
index 787a21a..2ab9bb0 100644
--- a/app/src/main/zip.ts
+++ b/app/src/main/zip.ts
@@ -14,9 +14,10 @@ const SKIP_FILES = new Set(['.soma/model.glb', '.soma/model.map.json', '.soma/bu
/**
* 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.
- * Die Projektumgebung (E67) legt die App beim Öffnen an und installiert dabei requirements.txt.
+ * Die Projektumgebung (E67) legt die App beim Öffnen an und installiert dabei requirements.txt. Bilder und Videos von
+ * soma render entstehen aus dem Code neu (E75, beim Hotwire 41 % der ZIP).
*/
-const SKIP_PATHS = new Set(['.soma/geometry', '.soma/anim', '.soma/results', '.soma/env']);
+const SKIP_PATHS = new Set(['.soma/geometry', '.soma/anim', '.soma/results', '.soma/env', 'renders']);
/** 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;
diff --git a/app/test/unit.mjs b/app/test/unit.mjs
index 18f6f08..0e97aab 100644
--- a/app/test/unit.mjs
+++ b/app/test/unit.mjs
@@ -291,8 +291,26 @@ try {
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/view-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/view-iso.png'] === 'PNG', JSON.stringify(inZip));
+ check('ZIP: ohne .soma/results, .soma/anim und renders/ (E75), mit Modell', inZip['model.py'] === 'x = 2\n' && inZip['.soma/results/thickness.glb'] === null
+ && inZip['.soma/anim/deckel.glb'] === null && inZip['renders/view-iso.png'] === null, JSON.stringify(inZip));
+
+ // Packen vor der ZIP (E75): Verlauf und Hashes bleiben. Unerreichbares geht nicht verloren: der Blob, den addAll oben aus
+ // dem Index genommen hat (lose), und ein Objekt, das nur in einem älteren Pack liegt (ohne --keep-unreachable weg).
+ const loose = async () => Number(/^count: (\d+)$/m.exec((await repo.run(['count-objects', '-v'])).out)?.[1] ?? -1);
+ const commitsBefore = (await repo.run(['log', '--format=%H'])).out;
+ fs.writeFileSync(path.join(tmp, 'unerreichbar.txt'), 'nur in einem alten Pack');
+ const orphan = (await repo.run(['hash-object', '-w', path.join(tmp, 'unerreichbar.txt')], true)).out.trim();
+ await repo.run(['tag', 'halten', orphan], true);
+ const packed = await repo.pack();
+ const packs = fs.readdirSync(path.join(old, '.git', 'objects', 'pack')).filter((f) => f.endsWith('.pack'));
+ check('pack(): ein Pack, keine losen Objekte, Verlauf gleich, fsck ohne Fehler', packed && packs.length === 1 && (await loose()) === 0
+ && (await repo.run(['log', '--format=%H'])).out === commitsBefore && (await repo.run(['fsck', '--no-dangling'])).ok, `${packed} ${packs} ${await loose()}`);
+ check('pack() ohne lose Objekte tut nichts', (await repo.pack()) === false);
+ await repo.run(['tag', '-d', 'halten'], true);
+ put('model.py', 'x = 3\n');
+ await repo.snapshot('Automatic snapshot on save');
+ check('pack() nach neuem Snapshot: Unerreichbares aus dem alten Pack bleibt erhalten', (await repo.pack()) === true
+ && (await repo.run(['cat-file', '-e', orphan])).ok && fs.readdirSync(path.join(old, '.git', 'objects', 'pack')).filter((f) => f.endsWith('.pack')).length === 1);
} finally {
fs.rmSync(gz, { force: true });
}