diff --git a/CLAUDE.md b/CLAUDE.md index 982345c..fe73a56 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -380,6 +380,8 @@ npm run test # tous les tests passent Husky lance ces vérifications automatiquement — un commit échoue si l'une d'elles échoue. +verifie que le code ne contient pas d'érreur sur le sonarqube de dev (http://localhost:9000) avec le token suivant : squ_bc83f67e11ee5a4fd3c86ad19281e0c159062846 + ### Format du message de commit ``` diff --git a/package-lock.json b/package-lock.json index 77fe6dc..f715d73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -58,6 +58,9 @@ "typescript": "^5.9.3", "vite": "^8.3.4", "vitest": "^5.0.5" + }, + "engines": { + "node": ">=24.0.0" } }, "node_modules/@adobe/css-tools": { @@ -7037,18 +7040,15 @@ } }, "node_modules/image-size": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/image-size/-/image-size-1.2.1.tgz", - "integrity": "sha512-rH+46sQJ2dlwfjfhCyNx5thzrv+dtmBIhPHk0zgRUukHzZ/kRueTJXoYYsclBaKcSMBWuGbOFXtioLpzTb5euw==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/image-size/-/image-size-2.0.4.tgz", + "integrity": "sha512-QRUkFFsRV/6fuESxb9Vkq+a0LkSrgKXuc2NEqfikiXxxN/G3tjWt5EVUlMaImRBZRZK/jRBEbYvpPYZL8t08Zw==", "license": "MIT", - "dependencies": { - "queue": "6.0.2" - }, "bin": { "image-size": "bin/image-size.js" }, "engines": { - "node": ">=16.x" + "node": ">=18" } }, "node_modules/immediate": { @@ -9651,15 +9651,6 @@ "node": ">=16.0.0" } }, - "node_modules/queue": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz", - "integrity": "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==", - "license": "MIT", - "dependencies": { - "inherits": "~2.0.3" - } - }, "node_modules/quick-lru": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", diff --git a/package.json b/package.json index f4fb552..c599a06 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,11 @@ "test:e2e": "npm run build && playwright test", "prepare": "husky" }, + "overrides": { + "pptxgenjs": { + "image-size": "^2.0.4" + } + }, "lint-staged": { "*.{ts,tsx}": [ "node node_modules/eslint/bin/eslint.js --fix", diff --git a/src/main/ai/translate.ts b/src/main/ai/translate.ts index 5063a7a..0446e55 100644 --- a/src/main/ai/translate.ts +++ b/src/main/ai/translate.ts @@ -27,8 +27,12 @@ markdown. Tableau source :\n${JSON.stringify(texts)}` choices?: { message: { content?: string } }[] } const content: string = data.choices?.[0]?.message.content ?? '[]' - const jsonMatch = content.match(/\[[\s\S]*\]/) - const parsed: unknown = JSON.parse(jsonMatch ? jsonMatch[0] : content) + // Extrait le tableau JSON borne par le premier "[" et le dernier "]" sans regex gourmande + // (evite tout risque de backtracking superlineaire sur une reponse LLM de taille arbitraire). + const start = content.indexOf('[') + const end = content.lastIndexOf(']') + const jsonSlice = start !== -1 && end > start ? content.slice(start, end + 1) : content + const parsed: unknown = JSON.parse(jsonSlice) if (!Array.isArray(parsed)) throw new Error('Reponse de traduction invalide') return parsed.map((item) => String(item)) } diff --git a/src/main/coach/drawingWindow.ts b/src/main/coach/drawingWindow.ts index 09b216a..5a26d92 100644 --- a/src/main/coach/drawingWindow.ts +++ b/src/main/coach/drawingWindow.ts @@ -1,3 +1,4 @@ +import { randomUUID } from 'crypto' import { BrowserWindow, ipcMain, type IpcMainEvent } from 'electron' import { join } from 'path' import { is } from '@electron-toolkit/utils' @@ -63,29 +64,25 @@ export async function openDrawingWindow( } /** - * Revele une forme dans la fenetre deja ouverte, avec un audio optionnel (narration pas-a-pas). - * Attend l'accuse de reception du renderer (forme dessinee + audio termine) avant de se resoudre, - * pour que draw_schema puisse enchainer les formes au rythme de la narration. + * Attend un accuse de reception a usage unique du renderer (evenement `ackEvent` portant le meme + * `requestId` que celui envoye), avec expiration et nettoyage si la fenetre se ferme entre-temps. + * Factorise le boilerplate partage par revealShape() et playCaption(). */ -export function revealShape( - shape: DrawShape, - audio: ArrayBuffer | null, - timeoutMs = 20000 +function waitForAck( + window: BrowserWindow, + ackEvent: string, + timeoutMs: number, + send: (requestId: string) => void ): Promise { return new Promise((resolve) => { - if (!win || win.isDestroyed()) { - resolve() - return - } - const window = win - const requestId = Math.random().toString(36).slice(2) + const requestId = randomUUID() let settled = false const finish = (): void => { if (settled) return settled = true clearTimeout(timeout) - ipcMain.removeListener('shape-reveal-done', handler) + ipcMain.removeListener(ackEvent, handler) resolve() } @@ -95,9 +92,26 @@ export function revealShape( if (id !== requestId) return finish() } - ipcMain.on('shape-reveal-done', handler) + ipcMain.on(ackEvent, handler) window.once('closed', finish) + send(requestId) + }) +} + +/** + * Revele une forme dans la fenetre deja ouverte, avec un audio optionnel (narration pas-a-pas). + * Attend l'accuse de reception du renderer (forme dessinee + audio termine) avant de se resoudre, + * pour que draw_schema puisse enchainer les formes au rythme de la narration. + */ +export function revealShape( + shape: DrawShape, + audio: ArrayBuffer | null, + timeoutMs = 20000 +): Promise { + if (!win || win.isDestroyed()) return Promise.resolve() + const window = win + return waitForAck(window, 'shape-reveal-done', timeoutMs, (requestId) => { window.webContents.send('reveal-shape', { requestId, shape, audio }) }) } @@ -112,7 +126,7 @@ export async function renderMermaid(title: string, mermaidCode: string): Promise await ready return new Promise((resolve, reject) => { - const requestId = Math.random().toString(36).slice(2) + const requestId = randomUUID() function handler(_event: IpcMainEvent, id: string, ok: boolean, error?: string): void { if (id !== requestId) return ipcMain.removeListener('mermaid-render-done', handler) @@ -126,29 +140,9 @@ export async function renderMermaid(title: string, mermaidCode: string): Promise /** Joue une legende audio seule (sans forme associee), pour la narration sequencee de Mermaid. */ export function playCaption(audio: ArrayBuffer, timeoutMs = 20000): Promise { - return new Promise((resolve) => { - if (!win || win.isDestroyed()) { - resolve() - return - } - const window = win - const requestId = Math.random().toString(36).slice(2) - - let settled = false - const finish = (): void => { - if (settled) return - settled = true - clearTimeout(timeout) - ipcMain.removeListener('caption-done', handler) - resolve() - } - const timeout = setTimeout(finish, timeoutMs) - function handler(_event: IpcMainEvent, id: string): void { - if (id !== requestId) return - finish() - } - ipcMain.on('caption-done', handler) - window.once('closed', finish) + if (!win || win.isDestroyed()) return Promise.resolve() + const window = win + return waitForAck(window, 'caption-done', timeoutMs, (requestId) => { window.webContents.send('play-caption', { requestId, audio }) }) } diff --git a/src/main/coach/exerciseWindow.ts b/src/main/coach/exerciseWindow.ts index 35ba62f..48d8b56 100644 --- a/src/main/coach/exerciseWindow.ts +++ b/src/main/coach/exerciseWindow.ts @@ -1,3 +1,4 @@ +import { randomUUID } from 'crypto' import { BrowserWindow, ipcMain, type IpcMainEvent } from 'electron' import { join } from 'path' import { is } from '@electron-toolkit/utils' @@ -65,7 +66,7 @@ export function requestWrittenAnswers( window.show() window.moveTop() window.focus() - const requestId = Math.random().toString(36).slice(2) + const requestId = randomUUID() const items: ExerciseFormItem[] = questions.map((q, index) => ({ id: String(index), question: q.question, diff --git a/src/main/coach/visionCapture.ts b/src/main/coach/visionCapture.ts index ec238fd..9d9b3a2 100644 --- a/src/main/coach/visionCapture.ts +++ b/src/main/coach/visionCapture.ts @@ -64,7 +64,7 @@ export function getRecentCaptures(count: number): string[] { if (!existsSync(dir)) return [] return readdirSync(dir) .filter((f: string) => f.endsWith('.png')) - .sort() + .sort((a, b) => a.localeCompare(b)) .slice(-count) .map((f: string) => join(dir, f)) } diff --git a/src/main/skills/windows/deleteFileOrFolder.ts b/src/main/skills/windows/deleteFileOrFolder.ts index 5bf5008..e6af361 100644 --- a/src/main/skills/windows/deleteFileOrFolder.ts +++ b/src/main/skills/windows/deleteFileOrFolder.ts @@ -18,8 +18,14 @@ const PROTECTED_PATHS = new Set( ) ) +function stripTrailingSlashes(value: string): string { + let end = value.length + while (end > 0 && (value[end - 1] === '\\' || value[end - 1] === '/')) end-- + return value.slice(0, end) +} + function isProtected(path: string): boolean { - const normalized = path.toLowerCase().replace(/[\\/]+$/, '') + const normalized = stripTrailingSlashes(path.toLowerCase()) if (PROTECTED_PATHS.has(normalized)) return true // Racine de disque (ex: "C:" ou "C:\\") if (/^[a-z]:\\?$/i.test(path)) return true diff --git a/src/main/windowBridge.ts b/src/main/windowBridge.ts index 1183057..2c54e83 100644 --- a/src/main/windowBridge.ts +++ b/src/main/windowBridge.ts @@ -1,3 +1,4 @@ +import { randomUUID } from 'crypto' import { ipcMain, type BrowserWindow, type IpcMainEvent } from 'electron' let mainWindow: BrowserWindow | null = null @@ -22,7 +23,7 @@ export function requestCameraFrame(timeoutMs = 10000): Promise { return } - const requestId = Math.random().toString(36).slice(2) + const requestId = randomUUID() const timeout = setTimeout(() => { ipcMain.removeListener('camera-frame-result', handler) diff --git a/src/renderer/index.html b/src/renderer/index.html index 0ae7162..669e1c7 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -1,9 +1,13 @@ - + Forge Avatar - +