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: Kopien der Skills im Dateibaum, Front Matter in der Dokumentansicht

Kai-Jungsthoefel94d989514109
diff --git a/app/src/main/files.ts b/app/src/main/files.ts
index 5044275..2d53aff 100644
--- a/app/src/main/files.ts
+++ b/app/src/main/files.ts
@@ -300,13 +300,15 @@ export function listFiles(root: string): FileNode[] {
return nodes.sort((a, b) => Number(b.dir) - Number(a.dir) || a.name.localeCompare(b.name));
};
const nodes = walk(root, '', 0);
- // Markierungen (E16) liegen versteckt in .soma/feedback/. Der Nutzer soll sie wiederfinden und erneut an den Agenten
- // geben können, deshalb kommt nur dieser Ordner mit. Neueste zuerst (der Name beginnt mit Datum und Uhrzeit).
- const fb = path.join(root, '.soma', 'feedback');
- try {
- if (fs.lstatSync(fb).isDirectory() && !fs.lstatSync(path.join(root, '.soma')).isSymbolicLink()) {
- nodes.push({ name: 'feedback', path: '.soma/feedback', dir: true, children: walk(fb, '.soma/feedback', 1).reverse() });
- }
- } catch { /* noch keine Markierung */ }
+ // Aus .soma/ kommen nur zwei Ordner mit, der Rest sind Zwischenstände und die Umgebung des Projekts (tausende Dateien).
+ // Markierungen (E16), damit der Nutzer sie wiederfindet und erneut an den Agenten geben kann, neueste zuerst (der Name
+ // beginnt mit Datum und Uhrzeit). Die Kopien der Skills (E17) zum Nachlesen, umgestellt wird im Panel „Skills“.
+ try { if (!fs.lstatSync(path.join(root, '.soma')).isDirectory()) return nodes; } catch { return nodes; }
+ for (const [name, newestFirst] of [['feedback', true], ['skills', false]] as const) {
+ const dir = path.join(root, '.soma', name);
+ try { if (!fs.lstatSync(dir).isDirectory()) continue; } catch { continue; }
+ const children = walk(dir, `.soma/${name}`, 1);
+ nodes.push({ name, path: `.soma/${name}`, dir: true, children: newestFirst ? children.reverse() : children });
+ }
return nodes;
}
diff --git a/app/src/main/watcher.ts b/app/src/main/watcher.ts
index 3c6a19f..1a34c14 100644
--- a/app/src/main/watcher.ts
+++ b/app/src/main/watcher.ts
@@ -5,8 +5,8 @@ import { affectsAnimation, affectsBuild } from '../shared/editable';
export const IGNORED_TOP = new Set(['.git', '.soma', 'output', 'exports', '__pycache__', 'node_modules', '.venv', 'venv', 'env']);
const topSegment = (rel: string) => rel.split(/[\\/]/)[0] ?? '';
-/** Markierungen (E16) stehen im Dateibaum: Änderungen dort frischen die Liste auf, bauen aber nie. */
-const isFeedback = (rel: string) => /^\.soma[\\/]feedback([\\/]|$)/i.test(rel);
+/** Markierungen (E16) und Kopien der Skills stehen im Dateibaum: Änderungen dort frischen die Liste auf, bauen aber nie. */
+const isShown = (rel: string) => /^\.soma[\\/](feedback|skills)([\\/]|$)/i.test(rel);
const isIgnored = (rel: string) => IGNORED_TOP.has(topSegment(rel)) || rel.split(/[\\/]/).includes('__pycache__');
/** Quelltext-Aenderung: dieselbe Regel wie beim Speichern im Editor (src/shared/editable.ts). */
const isSource = affectsBuild;
@@ -22,9 +22,9 @@ export function watchProject(dir: string, onSource: (rel: string | null) => void
try {
watcher = fs.watch(dir, { recursive: true }, (_evt, filename) => {
const rel = filename ? String(filename) : '';
- if (rel && isIgnored(rel) && !isFeedback(rel)) return;
+ if (rel && isIgnored(rel) && !isShown(rel)) return;
if (rel && affectsAnimation(rel)) onAnim(rel.replace(/\\/g, '/'));
- else if (!rel || (isSource(rel) && !isFeedback(rel))) onSource(rel || null);
+ else if (!rel || (isSource(rel) && !isShown(rel))) onSource(rel || null);
if (filesTimer) clearTimeout(filesTimer);
filesTimer = setTimeout(onFiles, 250);
});
diff --git a/app/src/renderer/filetree.ts b/app/src/renderer/filetree.ts
index b6ff902..2462471 100644
--- a/app/src/renderer/filetree.ts
+++ b/app/src/renderer/filetree.ts
@@ -6,8 +6,9 @@ import { el, menuItem, menus } from './ui';
/** Dateien, die die App verwaltet. Sie stehen eingeklappt unter „Vom Programm verwaltet“, damit der Baum ruhig bleibt. */
const MANAGED = new Set(['AGENTS.md', 'CLAUDE.md', '.gitignore']);
const TAGS: Record<string, string> = { 'model.py': 'model', 'output/model.step': 'result', 'NOTES.md': 'notes', 'requirements.txt': 'packages' };
-/** Ordner der Markierungen. Der Hauptprozess liefert ihn als einzigen Teil von .soma/ mit. */
+/** Ordner der Markierungen und der Kopien der Skills. Der Hauptprozess liefert nur diese beiden Teile von .soma/ mit. */
const FEEDBACK = '.soma/feedback';
+const SKILLS = '.soma/skills';
export const TEXT_EXT = /\.(py|md|txt|json|toml|cfg|ini|yml|yaml|gitignore|csv)$|^[^.]*$/i;
/** Bilder, die die Zeichenfläche als Hintergrund laden kann (alles, was Chromium als <img> anzeigt). */
export const IMAGE_EXT = /\.(png|jpe?g|gif|webp|bmp|svg)$/i;
@@ -61,7 +62,7 @@ const parentOf = (rel: string) => (rel.includes('/') ? rel.slice(0, rel.lastInde
* Was gesperrt ist, regelt `fileOpBlockReason`, dieselbe Regel prüft der Hauptprozess noch einmal.
*/
export class FileTree {
- private collapsed = new Set<string>(['#managed']);
+ private collapsed = new Set<string>(['#managed', SKILLS]);
private nodes: FileNode[] = [];
private edit: Edit | null = null;
private input: HTMLInputElement | null = null;
@@ -97,7 +98,8 @@ export class FileTree {
if (this.edit?.mode === 'rename' && !this.find(this.edit.node.path) && !this.submitting) { this.edit = null; this.input = null; }
const managed = nodes.filter((n) => !n.dir && MANAGED.has(n.name));
const feedback = nodes.find((n) => n.path === FEEDBACK);
- const rest = nodes.filter((n) => !managed.includes(n) && n !== feedback);
+ const skills = nodes.find((n) => n.path === SKILLS);
+ const rest = nodes.filter((n) => !managed.includes(n) && n !== feedback && n !== skills);
const rows: HTMLElement[] = [];
const ed = this.edit;
const walk = (list: FileNode[], depth: number, parent: string) => {
@@ -107,29 +109,33 @@ export class FileTree {
if (n.dir && n.children && !this.collapsed.has(n.path)) walk(n.children, depth + 1, n.path);
}
};
- walk(rest, 0, '');
- if (!rest.length && !ed) rows.push(el('div', { className: 'hint', textContent: 'No files yet.' }));
- // Markierungen (E16) aus .soma/feedback/: eigene Gruppe, neueste zuerst. Zum Wiederfinden und erneut an den Agenten geben.
- if (feedback?.children?.length) {
+ /** Kopf einer Gruppe unter den Projektdateien, liefert, ob sie aufgeklappt ist. `rel` macht den Kopf zum Ordner fürs Menü. */
+ const group = (key: string, ico: string, label: string, count: number, title: string, rel?: string): boolean => {
rows.push(el('div', { className: 'gap' }));
- const open = !this.collapsed.has(FEEDBACK);
- const head = this.button(0, open ? 'down' : 'right', 'image', 'Markups', String(feedback.children.length), 'dim');
- head.title = 'Images from “Mark up”, stored in .soma/feedback/. Click to open for markup, right-click to send the path to the agent or open in an image viewer.';
+ const open = !this.collapsed.has(key);
+ const head = this.button(0, open ? 'down' : 'right', ico, label, String(count), 'dim');
+ head.title = title;
head.setAttribute('aria-expanded', String(open));
- head.dataset.path = FEEDBACK;
- head.addEventListener('click', () => this.toggle(FEEDBACK));
+ if (rel) head.dataset.path = rel;
+ head.addEventListener('click', () => this.toggle(key));
rows.push(head);
- if (open) walk(feedback.children, 1, FEEDBACK);
+ return open;
+ };
+ walk(rest, 0, '');
+ if (!rest.length && !ed) rows.push(el('div', { className: 'hint', textContent: 'No files yet.' }));
+ // Markierungen (E16) aus .soma/feedback/: eigene Gruppe, neueste zuerst. Zum Wiederfinden und erneut an den Agenten geben.
+ if (feedback?.children?.length && group(FEEDBACK, 'image', 'Markups', feedback.children.length,
+ 'Images from “Mark up”, stored in .soma/feedback/. Click to open for markup, right-click to send the path to the agent or open in an image viewer.', FEEDBACK)) {
+ walk(feedback.children, 1, FEEDBACK);
}
- if (managed.length) {
- rows.push(el('div', { className: 'gap' }));
- const open = !this.collapsed.has('#managed');
- const head = this.button(0, open ? 'down' : 'right', 'lock', 'Managed by the app', String(managed.length), 'dim');
- head.title = 'The app creates these files and renews them with updates. There is no need to change them.';
- head.setAttribute('aria-expanded', String(open));
- head.addEventListener('click', () => this.toggle('#managed'));
- rows.push(head);
- if (open) for (const n of managed) rows.push(this.row(n, 1));
+ // Kopien der Skills (E17) aus .soma/skills/: zum Nachlesen, eingeklappt, weil es meist über ein Dutzend sind
+ if (skills?.children?.length && group(SKILLS, 'book', 'Skills', skills.children.length,
+ 'Copies of the skills this model uses, stored in .soma/skills/. Click to read, switch them on and off on the left under “Skills”.', SKILLS)) {
+ walk(skills.children, 1, SKILLS);
+ }
+ if (managed.length && group('#managed', 'lock', 'Managed by the app', managed.length,
+ 'The app creates these files and renews them with updates. There is no need to change them.')) {
+ for (const n of managed) rows.push(this.row(n, 1));
}
const hadFocus = !!this.input && document.activeElement === this.input;
this.root.replaceChildren(...rows);
diff --git a/app/src/renderer/markdown.ts b/app/src/renderer/markdown.ts
index 0d31074..c13b505 100644
--- a/app/src/renderer/markdown.ts
+++ b/app/src/renderer/markdown.ts
@@ -33,8 +33,12 @@ export function renderMarkdown(src: string, file: string, readOnly: boolean, dep
const root = el('article', { className: 'md' });
const dir = file.includes('/') ? file.slice(0, file.lastIndexOf('/') + 1) : '';
const lineAt = (pos: number) => { let n = 1; for (let i = src.indexOf('\n'); i >= 0 && i < pos; i = src.indexOf('\n', i + 1)) n++; return n; };
+ // Front Matter (Kopf der Skills zwischen zwei „---“): Daten für Programme. Als Markdown gelesen würde der ganze Kopf
+ // zu einer Überschrift (Text über „---“), deshalb steht er als Quelltext vorn und nur der Rest geht an den Lexer.
+ const fm = /^?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(src);
+ const bodyAt = fm ? fm[0].length : 0;
let tokens: Token[];
- try { tokens = lexer(src, { gfm: true }); } catch (e) {
+ try { tokens = lexer(src.slice(bodyAt), { gfm: true }); } catch (e) {
root.append(el('p', { className: 'md-err', textContent: `The file cannot be read as Markdown: ${e instanceof Error ? e.message : String(e)}` }));
return root;
}
@@ -159,7 +163,12 @@ export function renderMarkdown(src: string, file: string, readOnly: boolean, dep
el('tbody', {}, ...t.rows.map((r) => el('tr', {}, ...r.map((c) => cell(c, 'td')))))));
};
- root.append(...blocks(tokens, 0));
+ if (fm) {
+ const head = el('pre', { className: 'md-front', title: 'Front matter: data for the app, not part of the text', textContent: fm[1] });
+ head.dataset.line = '1';
+ root.append(head);
+ }
+ root.append(...blocks(tokens, bodyAt));
if (!root.childElementCount) root.append(el('p', { className: 'md-empty', textContent: readOnly ? 'Empty file.' : 'Empty file. “Edit” at the top lets you write in it.' }));
root.addEventListener('click', (e) => {
diff --git a/app/src/renderer/style.css b/app/src/renderer/style.css
index 50193b5..9a02c92 100644
--- a/app/src/renderer/style.css
+++ b/app/src/renderer/style.css
@@ -320,7 +320,7 @@ code { font-family:var(--mono); font-size:.95em; }
.md code { font:12px var(--mono); background:var(--s3); color:#e3c8a0; border-radius:4px; padding:1px 5px; }
.md pre { background:var(--s1); border:1px solid var(--line); border-radius:7px; padding:10px 12px; overflow:auto; }
.md pre code { background:none; color:#c9ced4; padding:0; font-size:12px; line-height:1.6; white-space:pre; }
-.md pre.md-html { font:12px/1.6 var(--mono); color:var(--tx3); white-space:pre-wrap; }
+.md pre.md-html, .md pre.md-front { font:12px/1.6 var(--mono); color:var(--tx3); white-space:pre-wrap; }
.md blockquote { border-left:3px solid var(--line2); padding:2px 0 2px 12px; color:var(--tx2); }
.md hr { border:0; border-top:1px solid var(--line2); margin:1.2em 0; }
.md .md-link { color:#7fb4ff; cursor:pointer; text-decoration:underline; text-decoration-color:rgba(127,180,255,.4); text-underline-offset:2px; }
diff --git a/app/src/shared/editable.ts b/app/src/shared/editable.ts
index b932ca4..51543a5 100644
--- a/app/src/shared/editable.ts
+++ b/app/src/shared/editable.ts
@@ -26,6 +26,8 @@ export function fileOpBlockReason(rel: string, op: 'create' | 'rename' | 'delete
// Markierungen (E16) gehören dem Nutzer: aufräumen und umbenennen ja. Neues legt dort nur „An Agent geben“ ab, das
// sperrt die Prüfung des Ordners selbst (.soma/feedback fällt unter die nächste Regel).
if (/^\.soma\/feedback\/[^/]+$/i.test(p)) return null;
+ // Kopien der Skills (E17): Das Panel schaltet sie mit project.json und AGENTS.md zusammen ein und aus
+ if (/^\.soma\/skills(\/|$)/i.test(p)) return 'Skills are switched on and off on the left under “Skills”.';
if (/^\.(soma|git)(\/|$)/i.test(p)) return 'Internal data of the app and of Git.';
if (op !== 'create' && /^model\.py$/i.test(p)) return 'model.py is the fixed entry point of the model.';
if (op === 'rename' && /^(inputs|parts)$/i.test(p)) return 'The agent looks for this folder by its name.';
diff --git a/app/test/skills.mjs b/app/test/skills.mjs
index 036392d..7ef2ab4 100644
--- a/app/test/skills.mjs
+++ b/app/test/skills.mjs
@@ -127,6 +127,34 @@ try {
await waitFor('ungespeichert', () => window.__t.saveState()?.dirtyFiles >= 3, 10000).catch(() => {});
check('Zählt als ungespeicherte Änderung (Kopie, project.json, AGENTS.md)', (await ev(() => window.__t.saveState())).dirtyFiles >= 3, String((await ev(() => window.__t.saveState())).dirtyFiles));
+ // Dateibaum: Kopien als eigene Gruppe „Skills“, eingeklappt, nur zum Lesen
+ await ev(() => window.__t.showPanel('files'));
+ await waitFor('Gruppe Skills im Dateibaum', () => window.__t.fileRows().includes('Skills'), 10000).catch(() => {});
+ const copies = fs.readdirSync(path.join(dir, '.soma', 'skills'));
+ const skHead = await ev(() => ({ rows: window.__t.fileRows(), count: document.querySelector('#tab-files .frow[data-path=".soma/skills"] .tag')?.textContent }));
+ check('Dateibaum: Gruppe „Skills“ eingeklappt, Zahl der Kopien, sonst nichts aus .soma', skHead.rows.includes('Skills') && skHead.count === String(copies.length)
+ && !skHead.rows.includes('3d-druck.md') && !skHead.rows.includes('project.json') && !skHead.rows.includes('env'), `${skHead.count}/${copies.length} ${skHead.rows.slice(-6).join(',')}`);
+ await ev(() => document.querySelector('#tab-files .frow[data-path=".soma/skills"]').click());
+ const skRows = await ev(() => window.__t.fileRows());
+ check('Aufgeklappt: die Kopien (3D-Druck), keine ausgeschaltete (Laser)', skRows.includes('3d-druck.md') && skRows.includes('cadquery.md') && !skRows.includes('laser.md'), skRows.join(','));
+ const skMenu = await ev(() => {
+ const row = document.querySelector('#tab-files .frow[data-path=".soma/skills/3d-druck.md"]');
+ const r = row.getBoundingClientRect();
+ row.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: r.left + 20, clientY: r.top + 5 }));
+ return [...document.querySelectorAll('#menu-ctx .mi')].map((b) => (b.disabled ? '-' : '') + b.textContent.replace(/(F2|Del)$/, ''));
+ });
+ check('Menü der Kopie: Öffnen und Pfad ja, Anlegen, Umbenennen und Löschen gesperrt', ['Open', 'Send path to agent', '-New file', '-Rename', '-Delete'].every((x) => skMenu.includes(x)), skMenu.join(','));
+ await ev(() => [...document.querySelectorAll('#menu-ctx .mi')].find((b) => b.textContent.startsWith('Open'))?.click());
+ await waitFor('Kopie im Code', () => window.__t.editor.state().file === '.soma/skills/3d-druck.md', 10000).catch(() => {});
+ const skEd = await ev(() => window.__t.editor.state());
+ check('„Open“ im Dateibaum: Kopie im Code-Panel, nur lesen', skEd.file === '.soma/skills/3d-druck.md' && skEd.readOnly && skEd.text.includes('# Skill: 3D printing (FDM)'), JSON.stringify({ f: skEd.file, ro: skEd.readOnly }));
+ await waitFor('Dokumentansicht', () => !!document.querySelector('.mdview .md h1'), 10000).catch(() => {});
+ const skDoc = await ev(() => { const md = document.querySelector('.mdview .md'); return { first: md?.firstElementChild?.className, front: md?.querySelector('.md-front')?.textContent ?? '', h: [...(md?.querySelectorAll('h1, h2') ?? [])].map((h) => h.textContent).slice(0, 2) }; });
+ check('Dokumentansicht: Kopf (Front Matter) als Quelltext vorn, erste Überschrift ist der Titel, kein Kopf als Überschrift', skDoc.first === 'md-front'
+ && skDoc.front.startsWith('title: 3D printing (FDM)') && !skDoc.front.includes('---') && skDoc.h[0] === 'Skill: 3D printing (FDM)', JSON.stringify(skDoc));
+ await shot('skills-dateibaum');
+ await ev(() => window.__t.showPanel('skills'));
+
// 3) Ansehen (nur lesen) und An Agent geben
await ev(() => window.__t.openSkill('3d-druck'));
await shot('skills-2-aktiv');
@@ -226,8 +254,15 @@ try {
check('Meldung nennt den laufenden Agenten', /is off\..*tell it/.test((await ev(() => window.__t.toast())).text), (await ev(() => window.__t.toast())).text);
// 6) Datei eines aktiven Skills fehlt: gemeldet, nicht neu angelegt (E28)
- fs.rmSync(path.join(dir, '.soma', 'skills', 'toleranzen.md'));
+ // Der Dateibaum ist dabei offen: Er folgt Änderungen in .soma/skills/ ohne Wechsel des Panels
await ev(() => window.__t.showPanel('files'));
+ await waitFor('toleranzen.md im Dateibaum', () => window.__t.fileRows().includes('toleranzen.md'), 10000).catch(() => {});
+ const hadTol = (await ev(() => window.__t.fileRows())).includes('toleranzen.md');
+ fs.rmSync(path.join(dir, '.soma', 'skills', 'toleranzen.md'));
+ await waitFor('Dateibaum ohne toleranzen.md', () => { const r = window.__t.fileRows(); return !r.includes('toleranzen.md') && r.includes('cadquery.md'); }, 10000).catch(() => {});
+ const tolRows = await ev(() => window.__t.fileRows());
+ check('Dateibaum folgt .soma/skills/: gelöschte Kopie verschwindet sofort, ausgeschalteter 3D-Druck fehlt', hadTol && !tolRows.includes('toleranzen.md')
+ && tolRows.includes('cadquery.md') && !tolRows.includes('3d-druck.md'), tolRows.join(','));
await ev(() => window.__t.showPanel('skills'));
await waitFor('Problem gemeldet', () => window.__t.skills().skills.find((x) => x.id === 'toleranzen')?.problems.length > 0, 10000);
const info = await ev(() => window.soma.project.current());
diff --git a/app/test/unit.mjs b/app/test/unit.mjs
index 336ded5..04cac50 100644
--- a/app/test/unit.mjs
+++ b/app/test/unit.mjs
@@ -224,6 +224,10 @@ try {
&& !affectsAnimation('animations/sub/x.py') && !affectsAnimation('model.py') && !affectsAnimation('animations/notes.md'));
check('parameters.json baut das Modell, ist im Editor nur lesbar, Umbenennen gesperrt, Löschen erlaubt', affectsBuild('parameters.json') && !affectsBuild('parts/parameters.json')
&& !!readOnlyReason('parameters.json') && !!fileOpBlockReason('parameters.json', 'rename') && fileOpBlockReason('parameters.json', 'delete') === null);
+ check('Kopien der Skills: im Editor nur lesbar, im Dateibaum kein Anlegen, Umbenennen, Löschen (Grund nennt das Panel), Markierungen schon',
+ /Skill/.test(readOnlyReason('.soma/skills/cnc.md') ?? '') && /“Skills”/.test(fileOpBlockReason('.soma/skills/cnc.md', 'rename') ?? '')
+ && !!fileOpBlockReason('.soma/skills/cnc.md', 'delete') && !!fileOpBlockReason('.soma/skills/neu.md', 'create') && !!fileOpBlockReason('.soma/skills', 'delete')
+ && fileOpBlockReason('.soma/feedback/a.png', 'delete') === null && /Internal/.test(fileOpBlockReason('.soma/project.json', 'delete') ?? ''));
// Werte aus dem Parameter-Panel (parameters.json): lesen, prüfen, schreiben, beim letzten Eintrag die Datei entfernen
const pmOut = path.join(tmp, 'params.mjs');