Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ jobs:
- name: Install dependencies
run: npm ci

# The tests' scratch vaults come from os.tmpdir(), which on a Windows
# runner is C:\Users\runneradmin\AppData\Local\Temp, the OS disk, while
# the checkout sits on D:. One MCP task update fsyncs four files there,
# and on a slow runner that took a 25 ms test past 8 s and failed main
# (vitest's 5 s limit, 2026-11-20). RUNNER_TEMP is on D:.
- name: Keep test scratch files on the runner's work disk
if: runner.os == 'Windows'
shell: pwsh
run: |
"TEMP=$env:RUNNER_TEMP" >> $env:GITHUB_ENV
"TMP=$env:RUNNER_TEMP" >> $env:GITHUB_ENV

- name: Verify terminal artifacts and legacy launchers
if: runner.os != 'Windows'
run: node --test tooling/scripts/terminal-artifact.test.mjs tooling/scripts/terminal-launcher.test.mjs
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zennotes/desktop",
"productName": "ZenNotes",
"version": "2.89.0",
"version": "2.90.0",
"description": "ZenNotes desktop shell",
"private": true,
"main": "./out/main/index.js",
Expand Down Expand Up @@ -69,7 +69,7 @@
"harper.js": "^2.7.0",
"highlight.js": "^11.10.0",
"jsxgraph": "^1.12.2",
"katex": "^0.16.15",
"katex": "^0.19.1",
"node-tikzjax": "^1.0.5",
"pele": "1.12.0",
"prettier": "^3.8.2",
Expand Down
39 changes: 36 additions & 3 deletions apps/desktop/src/main/note-creation-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { promises as fs } from 'node:fs'
import path from 'node:path'
import { randomInt } from 'node:crypto'
import { renameWithRetry } from './atomic-write'
import { isEphemeralRoot } from './ephemeral-vaults'

const metadataDirectory = '.zennotes/note-metadata'
const metadataSuffix = '.metadata.json'
Expand Down Expand Up @@ -113,17 +114,49 @@ export async function prepareNoteCreation(
throw error
})
if (!previous) {
await fs.rm(metadata, { force: true })
await startNoteCreation(root, rel)
return
}
if ((await readCreationMetadata(metadata)) !== null) return
const createdAt = Math.trunc(previous.birthtimeMs || previous.ctimeMs)
await publishCreationMetadata(metadata, createdAt, previous.mode & 0o777)
}

/**
* Record now as the creation date of a note this app is about to create,
* replacing any record an earlier note of the same name left behind.
*
* A new note cannot leave its date to the file's birthtime. On NTFS, a file
* created or renamed into a name that was deleted within the last 15 seconds
* gets the deleted file's birthtime back (file system tunneling), so a note
* deleted and made again under the same name showed the old note's date, and
* its first save wrote that date into this record for good. A note created
* outside the app still falls back to birthtime; there is nothing to record
* for it.
*/
export async function startNoteCreation(root: string, rel: string): Promise<void> {
if (isEphemeralRoot(root)) return
if (
rel.replaceAll('\\', '/').startsWith('.zennotes/') ||
!/\.(md|excalidraw)$/i.test(rel)
)
return
await publishCreationMetadata(await noteMetadataPath(root, rel), Date.now())
}

async function publishCreationMetadata(
metadata: string,
createdAt: number,
mode?: number,
): Promise<void> {
await fs.mkdir(path.dirname(metadata), { recursive: true })
const temporary = `${metadata}.${process.pid}.${Date.now()}${String(randomInt(1000000)).padStart(6, '0')}.tmp`
try {
const file = await fs.open(temporary, 'wx', previous.mode & 0o777)
const file = await fs.open(temporary, 'wx', mode)
try {
await file.writeFile(JSON.stringify({ version: 1, createdAt }) + '\n')
await file.writeFile(
JSON.stringify({ version: 1, createdAt: Math.trunc(createdAt) }) + '\n',
)
await file.sync()
} finally {
await file.close()
Expand Down
47 changes: 47 additions & 0 deletions apps/desktop/src/main/vault-creation-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,53 @@ describe('portable note creation metadata across desktop vault operations', () =
expect((await readNote(root, notePath)).createdAt).toBe(recreated.createdAt)
})

// NTFS hands a file made under a name deleted in the last 15 seconds the
// deleted file's birthtime (file system tunneling). Windows CI caught the
// case above reading that birthtime back; stat is made to answer the same
// way here, so every platform runs the Windows case.
it.each([
['createNote', (root: string) => createNote(root, 'inbox', 'Original')],
['a first writeNote', (root: string) => writeNote(root, 'inbox/Original.md', '# Original\n')],
['the MCP server', (root: string) => mcpVault.createNote(root, 'inbox', 'Original')]
])(
'a note made again after a permanent delete keeps its own date when the file system hands back the old birthtime, through %s',
async (_label, create) => {
const root = await makeVault()
const notePath = 'inbox/Original.md'
await seedNote(root, notePath)
await deleteNote(root, notePath)
invalidateNoteMetaCache(root)

const fsModule = await import('node:fs')
const realStat = fsModule.promises.stat
const abs = path.join(root, notePath)
const tunneled = vi
.spyOn(fsModule.promises, 'stat')
.mockImplementation(async (...args: Parameters<typeof realStat>) => {
const result = await realStat(...args)
if (path.resolve(String(args[0])) !== abs) return result
return Object.assign(result, {
birthtimeMs: ORIGINAL_CREATED_AT,
birthtime: new Date(ORIGINAL_CREATED_AT)
})
})
try {
const beforeCreate = Date.now()
const created = await create(root)
expect(created.path).toBe(notePath)
expect(created.createdAt).toBeGreaterThanOrEqual(beforeCreate)
expect(created.createdAt).toBeLessThanOrEqual(Date.now())

// The first save must not write the handed-back birthtime down.
const saved = await writeNote(root, notePath, '# Original\n\nEdited.\n')
expect(saved.createdAt).toBe(created.createdAt)
expect(await readMetadata(root, notePath)).toEqual({ version: 1, createdAt: created.createdAt })
} finally {
tunneled.mockRestore()
}
}
)

it.each([
['malformed JSON', '{"version":'],
['unsupported version', JSON.stringify({ version: 2, createdAt: ORIGINAL_CREATED_AT })],
Expand Down
12 changes: 6 additions & 6 deletions apps/desktop/src/main/vault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { noteMetadataPath, readNoteCreatedAt, prepareNoteCreation, removeNoteCreation } from './note-creation-metadata'
import { noteMetadataPath, readNoteCreatedAt, prepareNoteCreation, removeNoteCreation, startNoteCreation } from './note-creation-metadata'
import {
noteCommentsPath,
noteCommentsRoot,
Expand Down Expand Up @@ -3613,7 +3613,7 @@ export async function createNote(
const finalTitle = await uniqueTitle(dir, base)
const abs = path.join(dir, `${finalTitle}.md`)
const body = `# ${finalTitle}\n\n`
await removeNoteCreation(root, toPosix(path.relative(root, abs)))
await startNoteCreation(root, toPosix(path.relative(root, abs)))
await removeAgentEditRecord(root, toPosix(path.relative(root, abs)))
await fs.writeFile(abs, body, 'utf8')
invalidateNoteMetaCache(root, toPosix(path.relative(root, abs)))
Expand Down Expand Up @@ -3645,7 +3645,7 @@ export async function createExcalidraw(
}
}
const abs = path.join(dir, `${finalTitle}.excalidraw`)
await removeNoteCreation(root, toPosix(path.relative(root, abs)))
await startNoteCreation(root, toPosix(path.relative(root, abs)))
await removeAgentEditRecord(root, toPosix(path.relative(root, abs)))
await fs.writeFile(abs, JSON.stringify(emptyExcalidrawDocument(), null, 2), 'utf8')
invalidateNoteMetaCache(root, toPosix(path.relative(root, abs)))
Expand Down Expand Up @@ -3687,7 +3687,7 @@ export async function convertObsidianExcalidraw(root: string, rel: string): Prom
}
}
const destAbs = path.join(dir, `${finalTitle}.excalidraw`)
await removeNoteCreation(root, toPosix(path.relative(root, destAbs)))
await startNoteCreation(root, toPosix(path.relative(root, destAbs)))
await removeAgentEditRecord(root, toPosix(path.relative(root, destAbs)))
await fs.writeFile(destAbs, JSON.stringify(scene, null, 2), 'utf8')
invalidateNoteMetaCache(root, toPosix(path.relative(root, destAbs)))
Expand All @@ -3707,7 +3707,7 @@ export async function importExternalNote(root: string, sourceAbsPath: string): P
const finalTitle = await uniqueTitle(destDir, baseTitle)
const destAbs = path.join(destDir, `${finalTitle}.md`)
const body = await fs.readFile(source, 'utf8')
await removeNoteCreation(root, toPosix(path.relative(root, destAbs)))
await startNoteCreation(root, toPosix(path.relative(root, destAbs)))
await removeAgentEditRecord(root, toPosix(path.relative(root, destAbs)))
await fs.writeFile(destAbs, body, 'utf8')
await fs.rm(source, { force: true })
Expand Down Expand Up @@ -4561,7 +4561,7 @@ export async function duplicateNote(root: string, rel: string): Promise<NoteMeta
const copyTitle = await uniqueTitle(dir, `${baseTitle} copy`)
const destAbs = path.join(dir, `${copyTitle}${ext}`)
const body = await fs.readFile(abs, 'utf8')
await removeNoteCreation(root, toPosix(path.relative(root, destAbs)))
await startNoteCreation(root, toPosix(path.relative(root, destAbs)))
await removeAgentEditRecord(root, toPosix(path.relative(root, destAbs)))
await fs.writeFile(destAbs, body, 'utf8')
const meta = await readMeta(root, destAbs, folder)
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/mcp/vault-ops.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readNoteCreatedAt, prepareNoteCreation, removeNoteCreation, noteMetadataPath } from '../main/note-creation-metadata'
import { readNoteCreatedAt, prepareNoteCreation, removeNoteCreation, startNoteCreation, noteMetadataPath } from '../main/note-creation-metadata'
import { noteCommentsPath, noteCommentsRoot, relocateFolderTrees, relocateNote } from '../main/note-sidecars'
import { agentEditFolderPath, removeAgentEditRecord } from '../main/agent-edit-files'
import { fileIdentity, isSameFile } from '../main/same-file'
Expand Down Expand Up @@ -1841,7 +1841,7 @@ export async function createNote(
const finalTitle = await uniqueTitle(dir, base)
const abs = path.join(dir, `${finalTitle}.md`)
const content = body ?? `# ${finalTitle}\n\n`
await removeNoteCreation(root, toPosix(path.relative(root, abs)))
await startNoteCreation(root, toPosix(path.relative(root, abs)))
// A record left by an earlier note of this name would offer a bogus review.
await removeAgentEditRecord(root, toPosix(path.relative(root, abs)))
await fs.writeFile(abs, content, { encoding: 'utf8', flag: 'wx' })
Expand Down Expand Up @@ -1962,7 +1962,7 @@ export async function duplicateNote(root: string, rel: string): Promise<NoteMeta
const finalTitle = await uniqueTitle(dir, copyTitle(baseTitle))
const destAbs = path.join(dir, `${finalTitle}${ext}`)
const body = await fs.readFile(abs, 'utf8')
await removeNoteCreation(root, toPosix(path.relative(root, destAbs)))
await startNoteCreation(root, toPosix(path.relative(root, destAbs)))
await fs.writeFile(destAbs, body, { encoding: 'utf8', flag: 'wx' })
return await readMeta(root, destAbs, folder)
}
Expand Down
20 changes: 10 additions & 10 deletions apps/desktop/terminal-release.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
"release": {
"repository": "ZenNotes/tui",
"protocol": 1,
"version": "0.18.0",
"commit": "e443a8b0f3c8886dcdcac3aeec6269914968060b",
"version": "0.18.1",
"commit": "8b0582a524603a543f244f210225fbb6f06d6deb",
"artifacts": {
"darwin-arm64": {
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.0/zn_0.18.0_darwin_arm64.tar.gz",
"sha256": "3b57795dece8e11d7a500ee2b301621d3187145e7264b7242851fd54b473d2a9"
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.1/zn_0.18.1_darwin_arm64.tar.gz",
"sha256": "fb26893566292629ae8a232289abc9178dd8f0b6a13b0896eda2b77edb12662d"
},
"darwin-x64": {
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.0/zn_0.18.0_darwin_amd64.tar.gz",
"sha256": "da3bed8f9e436f5c3f3fc78007df704ac18be317890d85e19fc76ba2124b1476"
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.1/zn_0.18.1_darwin_amd64.tar.gz",
"sha256": "95242d01306e8915e775bed271a7152639151d7dc05ee5d5a17b58d815cee40d"
},
"linux-arm64": {
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.0/zn_0.18.0_linux_arm64.tar.gz",
"sha256": "cb4816d57f2a8b2f10748173cf232a04aaf0be40ab2c072fbeeb1e9380a1d48e"
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.1/zn_0.18.1_linux_arm64.tar.gz",
"sha256": "e6798937df01e68bd12a965261fd1a4c4ee7422575889b43329a3fd29a67892b"
},
"linux-x64": {
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.0/zn_0.18.0_linux_amd64.tar.gz",
"sha256": "7b738d0d5ce98a817d0017689e6fea464649240f42ba4baaae4a5b70de90e538"
"url": "https://github.com/ZenNotes/tui/releases/download/v0.18.1/zn_0.18.1_linux_amd64.tar.gz",
"sha256": "3b6f87a06abad7b0075bd6c9e304e96ff80387b2c8bef94defc97a240005677a"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/quicklook/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zennotes/quicklook",
"private": true,
"version": "2.89.0",
"version": "2.90.0",
"type": "module",
"description": "The macOS Quick Look preview for Markdown files: the page it renders and the Swift extension that serves it",
"homepage": "https://zennotes.org",
Expand Down Expand Up @@ -32,7 +32,7 @@
"gray-matter": "^4.0.3",
"highlight.js": "^11.10.0",
"jsxgraph": "^1.12.2",
"katex": "^0.16.15",
"katex": "^0.19.1",
"pele": "1.12.0",
"prettier": "^3.8.2",
"react": "^18.3.1",
Expand Down
4 changes: 2 additions & 2 deletions apps/share-viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zennotes/share-viewer",
"private": true,
"version": "2.89.0",
"version": "2.90.0",
"type": "module",
"description": "Read-only renderer for publicly shared ZenNotes, embedded by the zennotes.org website",
"homepage": "https://zennotes.org",
Expand Down Expand Up @@ -33,7 +33,7 @@
"gray-matter": "^4.0.3",
"highlight.js": "^11.10.0",
"jsxgraph": "^1.12.2",
"katex": "^0.16.15",
"katex": "^0.19.1",
"pele": "1.12.0",
"prettier": "^3.8.2",
"react": "^18.3.1",
Expand Down
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zennotes/web",
"private": true,
"version": "2.89.0",
"version": "2.90.0",
"type": "module",
"description": "ZenNotes web client for self-hosted and hosted deployments",
"homepage": "https://zennotes.org",
Expand Down Expand Up @@ -46,7 +46,7 @@
"harper.js": "^2.7.0",
"highlight.js": "^11.10.0",
"jsxgraph": "^1.12.2",
"katex": "^0.16.15",
"katex": "^0.19.1",
"pele": "1.12.0",
"prettier": "^3.8.2",
"react": "^18.3.1",
Expand Down
Loading
Loading