Conversation
❌ Deploy Preview for tiddlywiki-previews failed. Why did it fail? →
|
|
Confirmed: Jermolene has already signed the Contributor License Agreement (see contributing.md) |
📊 Build Size Comparison:
|
| Branch | Size |
|---|---|
| Base (master) | 2489.5 KB |
| PR | 2492.2 KB |
Diff: ⬆️ Increase: +2.8 KB
✅ Change Note Status
All change notes are properly formatted and validated!
📝 $:/changenotes/5.5.0/#9806
Type: feature | Category: nodejs
Release: 5.5.0
Filesystem dynamic stores with live reload via chokidar
🔗 #9806
👥 Contributors: Jermolene
📖 Change Note Guidelines
Change notes help track and communicate changes effectively. See the full documentation for details.
|
@Jermolene I last worked on this in late 2024 and was able to get it working using |
Thanks, I do recall your work on this. Avoiding the dependency is certainly desirable. |
|
Did you test this on a Windows machine? From time to time I do experiment with file watchers. Most of the time Windows Explorer completely kills the experience. It is able to lock files, and keeps them locked, in a way that completely confuses the watcher processes. So on Windows, we need to test that very carefully. |
That was my reasoning for starting with chokidar. It is widely used and battle tested. If we rolled our own alternative I think we’d struggle to match their test suite. |
For tiddlers loaded from a dynamic store, compute originalpath relative to the store directory so save-time path resolution lands at the correct location (previously produced URL-encoded absolute-path filenames). Add a tiddlerserializer module type mirroring tiddlerdeserializer: when a serializer is registered for a tiddler's content type, save as a single self-contained file with no .meta sidecar.
Not strictly related to dynamic stores, but very useful in connection with them
|
I have an working example at https://github.com/tiddly-gittly/TidGi-Desktop/blob/master/src/services/wiki/plugin/watchFileSystemAdaptor/WatchFileSystemAdaptor.ts
This will require many test case, If core provides this feature, I can finally not maintaining this by myself. I was planning to let copilot migrate it from my code to the core, but |
Thanks @linonetwo we should consolidate what we can into this PR. Note that (4) is already supported in this PR using dynamic store save filter.
We’ve held off implementing this feature before because of concerns like this. I think now it is essential that we offer this feature as soon as possible in order to be fungible with Obsidian for applications like LLM Wiki. I share your concerns about lost data. I would like to explore ways of implementing “running backups”, for example prior to deleting or overwriting files we copy/move them to a backup directory. It would echo one of the features I like about the single file edition of TW: that one can keep bashing the “save” button to make continuous backups as one works. |
|
@Jermolene .. I do not know if you did realise, that my tw-mcp server plugin is able to connect several llm clients at the same time to a single TW server. They all share the same $tw.wiki store. Most of the mcp-tools have direct access to the server $tw.wiki store and can manipulate it. If they do so the file syncer automatically syncs the info back to the filesystem. If files are written to the filesystem by an external editor. That's not detected. There are some exceptions. system tiddlers still need a server restart. ... I did not read the code from your plugin in detail. So I do not know if this info is actually useful. I only wanted to let you know. |
With this PR TiddlyWiki on the server gains the ability to scan tiddler directories for dynamic changes, and automatically reload the changed files.
This is a long standing request. @natecain proposed #176 in October 2013 to address it (it was merged but later reverted after problems were reported). There is also a feature request in #1530 from 2015. UPDATE 18/4/26: I missed #3060 too.
This PR adds a new
dynamicStore: { saveFilter, watch, debounce }property totiddlywiki.files. A dynamic store is a folder that is loaded at boot, watched live with chokidar, and then used as the save destination for tiddlers matching a configurable filter.The new dynamicStore optional property that marks the directory as a //dynamic store// that is both loaded at boot and actively watched on disk. The filesystem syncadaptor uses the watcher to pick up out-of-band changes (e.g. edits made by an external editor) and folds them into the running wiki. The object has the following properties:
true) set tofalseto disable the chokidar watcher for this store (tiddlers are still loaded and save-routed, but external changes are not picked up live)400) the per-file debounce window in milliseconds. File events that occur within this window of a previous event for the same file are coalesced, which avoids duplicated reloads during atomic-rename saves performed by many editors.Changes to a file on disk are diffed against the tiddler currently in the wiki before being reported, so self-writes performed by TiddlyWiki itself do not trigger spurious reload events. JavaScript module tiddlers (tiddlers with
type: application/javascriptand amodule-typefield) are never hot-reloaded, because that would require restarting the TiddlyWiki process.This example treats a sibling
content/folder as a dynamic store: every.mdfile is loaded at boot, every markdown tiddler saved by the wiki is routed back intocontent/, and external edits to those files are picked up automatically by chokidar.