Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(notes): distinguish mirrored notes from transcripts (#1276)
Henry Sud6335e78ffe9
diff --git a/src/helpers/markdownMirror.js b/src/helpers/markdownMirror.jsindex f1d6bc15f..ee55c9ef4 100644--- a/src/helpers/markdownMirror.js+++ b/src/helpers/markdownMirror.js@@ -203,6 +203,23 @@ class MarkdownMirror {return fs.existsSync(dirPath) ? dirPath : null;}+ // Note markdown opens with the frontmatter this mirror writes; transcript+ // companions open with "# <title>". BOM and CRLF are tolerated so a note an+ // external editor re-saved is still recognised.+ _isNoteMarkdownFile(filePath) {+ let fd;+ try {+ fd = fs.openSync(filePath, "r");+ const marker = Buffer.alloc(8);+ const bytesRead = fs.readSync(fd, marker, 0, marker.length, 0);+ return /^\uFEFF?---\r?\n/.test(marker.toString("utf8", 0, bytesRead));+ } catch {+ return false;+ } finally {+ if (fd !== undefined) fs.closeSync(fd);+ }+ }+_globNoteFiles(noteId) {if (!this._basePath) return [];const results = [];@@ -214,8 +231,13 @@ class MarkdownMirror {const dirPath = path.join(this._basePath, dir.name);const files = fs.readdirSync(dirPath);for (const file of files) {- if (file.startsWith(prefix) && file.endsWith(".md")) {- results.push(path.join(dirPath, file));+ const filePath = path.join(dirPath, file);+ if (+ file.startsWith(prefix) &&+ file.endsWith(".md") &&+ this._isNoteMarkdownFile(filePath)+ ) {+ results.push(filePath);}}}@@ -234,11 +256,13 @@ class MarkdownMirror {const dirPath = path.join(this._basePath, dir.name);const files = fs.readdirSync(dirPath);for (const file of files) {+ const filePath = path.join(dirPath, file);if (file.startsWith(prefix) &&- (file.endsWith("-transcript.md") || file.endsWith("-transcript.txt"))+ (file.endsWith("-transcript.txt") ||+ (file.endsWith("-transcript.md") && !this._isNoteMarkdownFile(filePath)))) {- results.push(path.join(dirPath, file));+ results.push(filePath);}}}diff --git a/test/helpers/markdownMirror.test.js b/test/helpers/markdownMirror.test.jsnew file mode 100644index 000000000..737f8b13a--- /dev/null+++ b/test/helpers/markdownMirror.test.js@@ -0,0 +1,105 @@+const test = require("node:test");+const assert = require("node:assert/strict");+const fs = require("node:fs");+const os = require("node:os");+const path = require("node:path");+const Module = require("node:module");++const originalLoad = Module._load;++Module._load = function loadWithElectronStub(request, parent, isMain) {+ if (request === "electron") {+ return { app: { isReady: () => false } };+ }+ return originalLoad.call(this, request, parent, isMain);+};++let markdownMirror;+try {+ markdownMirror = require("../../src/helpers/markdownMirror");+} finally {+ Module._load = originalLoad;+}++test("a note title ending in transcript keeps both mirrored files", (t) => {+ const basePath = fs.mkdtempSync(path.join(os.tmpdir(), "openwhispr-markdown-mirror-"));+ t.after(() => fs.rmSync(basePath, { recursive: true, force: true }));++ const note = {+ id: 7,+ title: "Meeting transcript",+ content: "Decisions and action items",+ created_at: "2026-07-21T12:00:00Z",+ transcript: JSON.stringify([+ { speaker: "speaker_0", timestamp: 0, text: "Hello from the meeting." },+ ]),+ };++ markdownMirror.init(basePath);+ markdownMirror.writeNote(note, "Personal");+ markdownMirror.writeTranscript(note, "Personal", {});++ const folderPath = path.join(basePath, "Personal");+ const notePath = path.join(folderPath, "7-meeting-transcript.md");+ const transcriptPath = path.join(folderPath, "7-meeting-transcript-transcript.md");++ assert.equal(fs.existsSync(notePath), true);+ assert.equal(fs.existsSync(transcriptPath), true);+ assert.equal(markdownMirror.getNotePath(note.id), notePath);+});++test("renaming a mirrored note cleans up both stale files and reveals the note", (t) => {+ const basePath = fs.mkdtempSync(path.join(os.tmpdir(), "openwhispr-markdown-mirror-"));+ t.after(() => fs.rmSync(basePath, { recursive: true, force: true }));++ const note = {+ id: 42,+ title: "Weekly sync",+ content: "Initial notes",+ created_at: "2026-07-21T12:00:00Z",+ transcript: JSON.stringify([+ { speaker: "speaker_0", timestamp: 0, text: "Hello from the meeting." },+ ]),+ };++ markdownMirror.init(basePath);+ markdownMirror.writeNote(note, "Personal");+ markdownMirror.writeTranscript(note, "Personal", {});++ const renamed = { ...note, title: "Renamed sync", content: "Updated notes" };+ markdownMirror.writeNote(renamed, "Personal");+ markdownMirror.writeTranscript(renamed, "Personal", {});++ const folderPath = path.join(basePath, "Personal");+ const notePath = path.join(folderPath, "42-renamed-sync.md");++ assert.deepEqual(fs.readdirSync(folderPath).sort(), [+ "42-renamed-sync-transcript.md",+ "42-renamed-sync.md",+ ]);+ assert.equal(markdownMirror.getNotePath(note.id), notePath);+ assert.match(fs.readFileSync(notePath, "utf-8"), /Updated notes$/);+});++test("a note file re-saved with a BOM or CRLF is still recognised as its note", (t) => {+ const basePath = fs.mkdtempSync(path.join(os.tmpdir(), "openwhispr-markdown-mirror-"));+ t.after(() => fs.rmSync(basePath, { recursive: true, force: true }));++ const note = {+ id: 11,+ title: "Quarterly plan",+ content: "Body",+ created_at: "2026-07-21T12:00:00Z",+ };++ markdownMirror.init(basePath);+ markdownMirror.writeNote(note, "Personal");++ const notePath = path.join(basePath, "Personal", "11-quarterly-plan.md");+ const original = fs.readFileSync(notePath, "utf-8");++ for (const rewritten of [original.replace(/\n/g, "\r\n"), `\uFEFF${original}`]) {+ fs.writeFileSync(notePath, rewritten, "utf-8");+ assert.equal(markdownMirror.getNotePath(note.id), notePath);+ }+});