Cuttlefish
Cuttlefish is a modular browser computing system and a member of the squidworks project, an effort to develop a distributed dataflow computing protocol.
Here, modular code is wrapped in dataflow descriptors and handles that allow rapid assembly of computing applications (programs!).
Cuttlefish also serves as the eyes into remote dataflow systems - meaning we can use it as a tool to assemble networks of computers to build, use, modify, and discover distributed programs.
How it Works
Hunks: Modular Code Blocks
Cuttlefish runs programs that are made of 'hunks' - each hunk is a small block of code. In the browser, these are ECMAScript Modules that are loaded from the server and dropped into the client at runtime.
Typed Data Interfaces
Hunks interface with the rest of the world through data ports - inputs and outputs - and their state variables. Each of these interfaces is typed - this helps us when we serialize messages (Cuttlefish is made for networks) - and helps everyone understand what hunks are meant to do.
Typing is rendered in /typeset.js
- we can only connect outputs to inputs when a function exists here to copy (and convert) data from the output-type to the input-type. These functions are directional!
Flowcontrolled Runtime
When Cuttlefish is running, it ferries data between hunk outputs to inputs, and gives each hunk some time to operate on those inputs, producing new outputs. By connecting different hunks in graphs, we can develop programs.
Data ferrying takes place according to a set of flowcontrol rules: data must be explicitly taken off of an input port before an output can push more data towards it. This means that processes which take time - and messages that have to traverse a network - don't overrun one another. It also means that cuttlefish is buffer free - this is a big win for systems where order of execution should be maintained, and where responsiveness is desired.
Polymorphic Hunks
To handle some complexity - particularly with typing - we can write hunks whose inputs and outputs change based on some of their state variables. For an example of this, see hunks/flowcontrol/syncpressure.js
.
Usage
To use Cuttlefish, we can serve it locally as described here and load it from the browser. This makes local development easier.
A menu is accessible on right-click. Here, we can add new hunks, and save / load programs - these are just lists of hunks, their state, and their connections. For a program to appear in the 'restore context' menu, just drop that .json in the /save/contexts/cuttlefish
folder. TBD is a server-side architecture to make this all sing and dance.
To connect an output to an input, we just drag that output onto an input. To disconnect them, we can right-click on the wire between them.
To delete hunks, right click on their title bar. We can also copy hunks, or reload them from source (which works pretty well but isn't bulletproof: careful of leftover DOM elements).
Running Locally
Cuttlefish emerges from a small node.js server, and the best way to develop / use it is still to run a local copy of this on your machine.
First, you should install node.js, if you're on a Mac / Unix (Raspberry Pi!), I would highly recommend NVM, and windows has an installer that works brilliantly.
Then, we need to install a few packages. Clone this repo wherever you'd like in your machine, cd
to that directory, and run:
npm install express
If you just want to run the browser tools, you're now done. If you want to use CF to connect to hardware, do:
npm install ws
and
npm install serialport