I was looking at the very cool isaacvando/rtl and noticed the tip to get a "hot reloading" experience.
That got me thinking why can't we just do this using basic-cli.
Could we implement something simple so that cli apps can easily implement a --watch command. In this case, rtl could watch a directory of template files and when something changes, rebuild the generated roc code.
I did some research and came up with the following idea. I don't have capacity to implement this right now, but I think it would be a cool feature to have, and so if anyone else would like to learn more about platform development this could be a fun project to work on.
Basically the idea is to implement a single Effect, which I've called Dir.snapshot : Str -> Task (List Str) _. The way it works is that whenever you call this effect, it returns a list of the file paths that have changed since the last time you called it.
So the first time you call this function, it returns an empty list. After some time you might call it again, and it returns a list of file paths that have changed since the first time you called it... and so on.
To use this in a cli app, you might do some things, check how long you spent since the last call and use Sleep.millis to wait until you want poll again for any changes in a loop, or until the user presses Ctrl+C to kill the process.
You might implement the effects in the platform as follows.
# Effect.roc
dirSnapshot : List U8 -> Effect (Result (List Str) Str)
# Dir.roc
## Take a snapshot of a directory and its contents, returns a list of file
## paths that have changed since the last snapshot.
snapshot : Str -> Task (List Str) [DirErr Err]
snapshot = \path ->
Effect.dirSnapshot path
|> InternalTask.fromEffect
For the implementation in the host lib.rs, you will need to implement an effect. I think this is all that would be required.
pub extern "C" fn roc_fx_dirSnapshot(pathStr: RocStr) -> RocResult<RocList<RocStr>, RocStr>
Now for implementation under the hood, I was thinking of a couple of different options; 1. something simple and syncronous, 2. something more complex and streaming. For both of these though the key thing is to keep track only of the files in the folder, and flag if they have changed -- so when roc comes calling using roc_fx_dirSnapshot we can simply serialise these files into a RocList.
For 1. We could recursively scan through the directory and subdirectories and compare the files against the last check. This might be simpler to implement, but would be significantly more work each time the snapshot is called.
For 2. Maybe we could use tokio runtime (which is already there) to spawn a thread and use channels to communicate between the main thread and the spawned thread. The spawned thread could be responsible for watching the directory using something like the notify crate, which recieves events each time a file changes (create, modify, delete). The thread would take these events and update our datastructure of the file state since last snapshot.
I'm definitely glossing over some details here... but wanted to share at least the bones.
Let me know if your interested.
Last updated: Jun 16 2026 at 16:19 UTC