## Home directory
Pinokio stores everything inside a centralized location (**Pinokio Home Directory**). This means you can:
1. Remove apps simply by deleting folders (No messy sysetm-wide installed files and DLLs)
2. Back up either the entire workspace or individual apps simiply by backing up folders.

When you first install Pinokio, you will be asked to set the **home** folder path.
You can also update it later in the settings tab.
---
## Self-contained File System
The top level folders under the Pinokio home directory look like the following
> We'll use the `/PINOKIO_HOME` notation to refer to the pinokio home directory from this point.
>
> The `/PINOKIO_HOME` folder is whichever folder you set as your Pinokio home.
```
/PINOKIO_HOME
/api
/stable-diffusion-webui.git
/comfyui.git
/brushnet.git
...
/bin
/miniconda
/homebrew
/py
/drive
/drives
/peers
...
/pip
/cache
/logs
```
### /api
The `api` folder is where the downloaded app repositories are stored. An API folder can contain either of the following:
1. **downloaded from git:** repositories you downloaded from git.
2. **locally created:** you can manually create folders and work from there.
### /bin
The `bin` folder stores all the binaries commonly used by AI engines.
- **miniconda:** for conda environment
- **brew:** for dealing with homebrew on macs
- **python** (and `pip`)
- **node.js** (and `npm`)
- etc.
Things installed into the `/bin` folder can be shared across multiple apps in the `/api` folder.
### /drive
The `drive` folder stores virtual drives, used for deduplicating redundant files to save the disk space, sharing data across multiple apps, and overall separating data from application for many useful scenarios.
> Learn more about virtual drives [here](#virtual-drive)
### /cache
The `cache` folder stores cache files programmatically downloaded or generated by apps (through `pip`, `torch`, `huggingface-cli`, etc.)
### /logs
The `logs` folder contains the logs, essential for debugging when something doesn't work.
---
## Distributed File URI
Pinokio uses a unique **distributed URI system** that lets you:
- Reference **local files**
- With **universally unique identifiers**
Let's first take a look at the most obvious option--Relative file paths.
### Relative Path
A URI can be a relative path. The path is resolved relative to the currently running script.
Let's say we have a folder at `/PINOKIO_HOME/api/myapp`, which looks like this:
```
/myapp
start.js
subroutine.json
```
And here's what `start.js` looks like:
```json
// start.js
module.exports = {
"run": [{
"method": "script.start",
"params": {
"uri": "subroutine.json"
}
}]
}
```
In this example, the `start.js` script calls another script named `subroutine.json`. This is a relative path.
The Pinokio interpreter automatically resolves the path of `subroutine.json` as the same folder that contains `start.js`, which is `/PINOKIO_HOME/api/myapp`.
So the `script.start` call will look for the file `/PINOKIO_HOME/api/myapp/subroutine.json` and run that script.
### Git Path
The relative path is enough for most cases, but what if the script you want to run is NOT from the same repository? What if you want to download a remote repository and run some script inside it?
This is where the Git URI scheme comes in.
#### Specification
This goal is achieved by adopting the [git url protocol](https://www.git-scm.com/docs/http-protocol#_url_format).
```
The processor is the CPU of Pinokio. It follows the same scheme all modern CPUs implement ([fetch-decode-execute cycle](https://en.wikipedia.org/wiki/Instruction_cycle#Summary_of_stages))
1. **[Fetch (Loader)](fetch):** The loader engine instantiates the state machine (including the memory as well as `self`, which refers to its own code)
2. **[Decode (Template)](decode):** The template engine takes a template expression and instantiates it using the current state provided by the loader
3. **[Execute (Runner)](execute):** The runner takes the instantiated request and executes it.
## Fetch
The "Fetch" step resolves locally installed scripts and loads them to memory.

### Resolve Script
The first step is to resolve the script URI. This involves:
1. Checking if the specified HTTP git URI is already installed locally.
2. If it is installed, resolving the local path, so we can access the actual files.
#### Syntax
```json
{
"uri":
## input
An `input` is a variable that gets passed from one RPC call to the next. Not all RPC APIs have a return value, but the ones that do, will pass down the `input` value to the next step.

There are two types of `input`:
1. **Return values between steps:** The `input` value passed into `run[1]`, ... `run[run.length-1]` steps. Basically, these are values that one step passes on to the next. `run[0]` can't have this since there is no previous step to `run[0]`.
1. **Initial script launch parameter:** The `input` value passed into `run[0]`.
- By default, this value will be `null` for `run[0]` since there is no "previous step".
- But it is possible to pass in custom `input` values to the first step `run[0]`
- **script.start params:** You can launch scripts programmatically using the [script.start](#scriptstart) API. And when you call the method, you can pass an additional `params` parameter. This will be passed into the first step `run[0]` as `input`.
- **pinokio.js menu item params:** You can construct the menu items UI in [pinokio.js](#pinokiojs) with an array attribute named `menu`, where each item may contain an `href` attribute, which will create a menu item that launches a script at the specified URI. You can also pass an additional `params` object along with the `href`, and this `params` object will be passed to the first step `run[0]` of the script as `input` when it's launched through the menu item.
Let's take a look at an example:
```json
{
"run": [{
"id": "run",
"method": "gradio.predict",
"params": {
"uri": "http://127.0.0.1:7860",
"path": "/answer_question_1",
"params": [
{ "path": "https://media.timeout.com/images/105795964/750/422/image.jpg" },
"Explain what is going on here"
]
}
}, {
"method": "log",
"params": {
"json2": "{{input.data[0]}}"
}
}]
}
```
In the example above, we are:
1. Making a request to `http://127.0.0.1:7860` using the [gradio.predict](#gradiopredict) API.
2. The return value of the [gradio.predict](#gradiopredict) gets passed down to the next step `log`.
3. The `log` takes the `input` and instantiates the template `{{input.data[0]}}` and logs the result to the terminal.
---
## args
args is equivalent to the `input` of the first step (`run[0]`).
Sometimes you may want to pass in some parameters when launching a script, and make use of the parameter object throughout the entire script.
You can't do this with [input](#input) because the input variable gets set freshly for every step.
Let's take a look at an example (a file named `launch.json`):
```json
{
"run": [{
"method": "log",
"params": {
"json2": "{{input}}"
}
}, {
"method": "log",
"params": {
"json2": "{{args}}"
}
}]
}
```
We may launch this script with the following [script.start](#scriptstart) API call:
```json
{
"run": [{
"method": "script.start",
"params": {
"uri": "launch.json",
"params": {
"a": 1,
"b": 2
}
}
}]
}
```
This will print:
```
{"a": 1, "b": 2}
{"a": 1, "b": 2}
```
1. The first line is from the first step, using the `input` value available at `run[0]`.
2. The second line is from the second step, usin the `args` value.
Note that the `input` value and `args` value will always be the same for `run[0]`.
---
## local
The local variable is every variable prefixed with `local.`. For example:
- `local.items`
- `local.prompt`
Local variables are reset whenever the script finishes running, which means if you run a script once, and run it again, they will always start from scratch.
You can set local variable values with [local.set](#localset) API.
---
## self
The `self` refers to the script itself.
A `run` script looks like this:
```json
{
"daemon":
Pinokio script is a declarative markup that can shell commands, work with files, make network requests, and pretty much everything you need to automatically install and run ANYTHING on a computer.
It is written in JSON, and can also be written in JavaScript (which returns the resulting JSON) in case you need to make them dynamically change.
---
## fs
- [fs.write](#fswrite)
- [fs.read](#fsread)
- [fs.rm](#fsrm)
- [fs.copy](#fscopy)
- [fs.download](#fsdownload)
- [fs.link](#fslink)
- [fs.open](#fsopen)
- [fs.cat](#fscat)
### fs.write
#### syntax
The `fs` api provides a simple way to write `json`, `text`, or `buffer` to the file system.
```json
{
"method": "fs.write",
"params": {
"path": 
This is an example
Just like `scripts`, you can write a UI using nothing but JSON (or JavaScript).
## components
For every project, you just need to think about three UI components:
1. **shortcut:** displayed on the home page. Can be configured with [pinokio.js](#pinokiojs)
2. **app:** The actual UI layout. Can be configured with [pinokio.js](#pinokiojs)
3. **info:** listed on the discover page and on https://pinokio.computer. Can be configured with [pinokio_meta.json](#pinokio_metajson)
### 1. shortcut
how the app is displayed on pinokio once downloaded. You can script this with [pinokio.js](#pinokiojs)

### 2. app
what the installed app page looks like.
You can script this with [pinokio.js](#pinokiojs).

### 3. info
how the app is displayed on the discover page and on https://pinokio.computer.
You can script this with [pinokio_meta.json](#pinokio_metajson).

---
## pinokio.js
Building a UI requires only a single file named `pinokio.js`. Simply place a file named `pinokio.js` in the project root folder.
The `pinokio.js` file describes both:
1. **Shortcut UI**
2. **App UI**
> **What if there is no `pinokio.js` file?**
>
> In this case, Pinokio will do its best to generate a minimal UI for you:
>
> 1. The shortcut UI will simply display the folder name as its title, and a default icon.
> 2. The app UI will display all `js` or `json` files inside the project root folder.
But in most cases you will want to write a simple `pinokio.js` file to build your own custom UI.
### syntax
```javascript
module.exports = {
"version":