tidalcycles / Tidal

Pattern language
http://tidalcycles.org/
GNU General Public License v3.0
2.24k stars 255 forks source link

tidal "safe mode" for use with (web) collaborative/shared editors #627

Open jwaldmann opened 4 years ago

jwaldmann commented 4 years ago

In collaborative live coding, there's always the problem that (by malice or by accident) some input can extract information from the system that runs tidal, or worse. Think of sending :! echo wat to ghci, and work from there ...

See discussion at https://github.com/munshkr/flok/issues/2 They want to have a language-agnostic solution, since their editor is.

I can imagine something that works just for tidal - since this is Haskell, and we have strong typing, we can simply forbid IO. Other languages can't.

I have experience with a similiar problem: automatically grading student (Haskell) programming exercises. My solution is that I force their code to match some blueprint (they can only fill in holes in specific places - for tidal, I imagine this would be _ in d1 $ _) and the compiler will check that the code is properly typed (in our case, the argument must be :: Pattern ControlMap).

I know this would exclude some tidal coding tricks (do { let foo = ... ; d1 $ .. ; d2 $ .. }) since this does not match the pattern, and you could still DOS the server (d1 $ let x = x in x) but so be it.

Summary: I can imagine an executable that

This would also solve the problem of "where does tidal find its boot file", because this will be baked into the executable. - Well, it'll be traded for the problem that mueval needs to find the tidal modules for type checking and evaluation.

jwaldmann commented 4 years ago

Is this "minitidal" (#452)? Not really, my plan is to use mueval/hint. You mention this option in the linked issue.

yaxu commented 4 years ago

Hi @jwaldmann

A drop-in replacement for ghci would be amazing. If we could make it redistributable without the whole of ghc, that would be a game changer.. However, this is unfortunately difficult. https://github.com/haskell-hint/hint/issues/80

There has been some work on this sort of thing in the past.

I once made this: https://github.com/yaxu/tidal-websocket

In the 'data' folder is a html-based editor (using codemirror) that sent code to the websocket.

It would need some fixes up to work with newer tidal..

There was some discussion towards formalising the protocol here: https://github.com/tidalcycles/Tidal/issues/159

https://twitter.com/tidalbot/ is no longer working, but it used to use hint too.

I also made a django-based website in the past that rendered patterns as well: https://github.com/yaxu/patternlib

That bitrotted too..

jwaldmann commented 4 years ago

Hi.

I just made this https://github.com/jwaldmann/safe-tidal-cli (very naive) and I am trying to declare it as a repl for flok https://github.com/munshkr/flok/issues/64

The safe-tidal-cli is working locally (I send text to stdin, it sends commands to SuperDirt as it should). I am actually surprised that it found the Tidal library! But, ghci also finds it, since I did cabal install --lib tidal.

[EDIT] connection to flok is working now.

Of course, this repl needs to be made more robust, it needs a better input parser, better error reporting and so on.

[EDIT] and I think it will totally not solve the "make tidal distribution/deploy easier" problem: Hint loads Sound.Tidal.Context, so this needs to be installed first.

jwaldmann commented 4 years ago

I now have a version that solves the conflict

I am wrapping the Tidal functions that produce IO, don't expose the constructor, and the wrapper is a monad as well, see https://github.com/jwaldmann/safe-tidal-cli/blob/master/src/Sound/Tidal/Safe/Context.hs

This does not allow code blocks let foo = bar because we can't change the state of the ghci session.

kuhy commented 6 months ago

Hi.

I just made this https://github.com/jwaldmann/safe-tidal-cli (very naive) and I am trying to declare it as a repl for flok munshkr/flok#64

The safe-tidal-cli is working locally (I send text to stdin, it sends commands to SuperDirt as it should). I am actually surprised that it found the Tidal library! But, ghci also finds it, since I did cabal install --lib tidal.

[EDIT] connection to flok is working now.

Of course, this repl needs to be made more robust, it needs a better input parser, better error reporting and so on.

[EDIT] and I think it will totally not solve the "make tidal distribution/deploy easier" problem: Hint loads Sound.Tidal.Context, so this needs to be installed first.

Why just don't run it inside a container? I think it's so much easier. Here is my working example: https://github.com/kuhy/tidalbox