# Motivation
Context switching is expensive. It takes time and effort to switch from one task to another, and it takes time and effort to switch back.
Minimize context switching as much as possible. When it does happen, make it as cognitively lightweight as possible. Workflows provide the needed structure to minimize context switching by automating repetitive tasks and providing a consistent interface for interacting with the environment.
Mew is a workflow automation platform that provides hooks, schedules, tasks, and triggers along with integrations for various services and devices. It is designed to be a flexible and extensible platform for automating tasks and workflows, Prompting for user input when neccesary, and displaying information about the tasks and workflows that are currently running, so that the user can switch between tasks and workflows with minimal cognitive overhead.
# Architecture
Implementing workflow automation is complicated. Red tape, security concerns, and the need to support a wide variety of devices and services make it difficult to implement a workflow automation that is both secure and easy to use, and this also makes it slow to deploy new workflows and to update existing workflows.
## Security
Devices often have significant constraints placed on them that make it difficult to implement a secure workflow automation. For example, a user account may not have the necessary permissions to install software or to access certain files or services. A device may not have the necessary resources to host workflow automation, or it may not have the necessary network connectivity to communicate with other devices or services.
## Deployment
Normally, implementing a workflow automation requires deploying code to infrastructure that makes
it publicly accessible, like a server or a cloud service, and then deploying code to the devices
that allow the devices to invoke that workflow that is managed by the server.
Mew is distributed, which means that every service and/or device that will participates in the
workflow will have a corresponding piece of software that mew calls an "agent". The agent
is responsible for listening for triggers, collecting enough infomation about the environment
to decide if it should execute a task, and then executing the task, which may involve calling
other agents or services.
## Components
- **Agent**: The agent is a program that runs on a device or service, possibly within a particular
context, like a user session or a network. The agent is responsible for:
- Listens for triggers and executes tasks
- Emitting events to trigger tasks on other agents
- **Task**: A task is a unit of work that an agent can execute. It may involve calling other agents
or services, or it may involve interacting with the local environment by running scripts or commands.
- **Trigger**: A trigger is a condition that causes an agent to execute a task. Triggers can be
time-based, event-based, or condition-based.
in practice, almost every installation consists of
- A system agent, responsible for
- responding to system events, such as login or startup
- Typically implemented as a systemd service on linux or as a LaunchAgent or LaunchDaemon on macOS
- and for managing the lifecycle of other agents.
- a network agent that is responsible for
- communicating with other network agents over a vpn or the internet,
- and several local agents that are responsible for
- interacting with the local environment or
- with services on behalf of the user that owns the local environment.
### System Agent
The system agent can responsible for managing the lifecycle of other agents.
Agents can be implemented as a rust crate that has a public `start` function. If so, the system agent
can call the start function of each agent that it is configured to.
# Insallation
## Install `rust`
This project is written in Rust. You need to install the Rust toolchain to build it.
https://rustup.rs/
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
## Clone this repository
This repository is managed with `pijul`. It's a distributed version control system like `git`. You can install it with `cargo`.
Check the installation instructions here to see if your system requires any additional dependencies:
https://pijul.org/manual/installing.html
```bash
cargo install pijul --version 1.0.0-alpha.1
```
Now you can clone this repository.
```bash
pijul clone https://nest.pijul.com/NyanHelsing/mew
```
## Build the project
This project uses `mise` as a package manager and script runner. You can install it with:
```bash
curl https://mise.run | sh
```
```bash
cd mew
mise trust # Allow mise to run scripts in this repository
mise install # Install dependencies
mise run deploy # Build the project and link entry points
```
# Usage
## Start the agent at boot
```bash
mew daemonize
```
# Development and Contribution
In order to push changes, you'll need to install a more up-to-date version of `pijul` than the one available on `crates.io`. You can do this by cloning the `pijul` repository and building it from source.
https://discourse.pijul.org/t/ssh-to-nest-not-working/1267
```bash
pijul clone https://nest.pijul.com/pijul/pijul
cd pijul
pijul reset --force
cargo update
cd pijul-remote
cargo add thrussh@0.35.6
cargo update
cd ..
cargo build --release
cargo install --path ./pijul
```
with this change in place, ssh should work as expected.
> Note: You may still need to create an account on the nest before you can push changes.
```bash
cd ~/mew
pijul push username@remote:/repository-name
```