bcbd1bdb22
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
145 lines
5.7 KiB
Plaintext
145 lines
5.7 KiB
Plaintext
---
|
|
title: Server & CLI
|
|
icon: terminal
|
|
description: Daemon + CLI for managing workspaces from the shell.
|
|
---
|
|
|
|
## Overview
|
|
|
|
Two companion packages to the core SDK:
|
|
|
|
- **[`@struktoai/mirage-server`](https://github.com/strukto-ai/mirage/tree/main/typescript/packages/server)**, a Fastify daemon that owns workspaces in-process and exposes them over HTTP (`/v1/workspaces`, `/v1/jobs`, ...).
|
|
- **[`@struktoai/mirage-cli`](https://github.com/strukto-ai/mirage/tree/main/typescript/packages/cli)**, a `commander` CLI that speaks to the daemon. Mirrors Python's `mirage` CLI 1:1.
|
|
|
|
The CLI is stateless. Long-running state lives in the daemon; the CLI auto-spawns one on the first `mirage workspace create` if none is running.
|
|
|
|
## Install
|
|
|
|
```bash
|
|
npm install -g @struktoai/mirage-cli
|
|
```
|
|
|
|
This pulls in `@struktoai/mirage-server` transitively (the CLI spawns the daemon from the server package's installed `bin/daemon.js`).
|
|
|
|
## Create a workspace
|
|
|
|
Write a YAML config:
|
|
|
|
```yaml
|
|
# config.yaml
|
|
mounts:
|
|
/:
|
|
resource: ram
|
|
mode: write
|
|
```
|
|
|
|
Then:
|
|
|
|
```bash
|
|
mirage workspace create config.yaml
|
|
```
|
|
|
|
The CLI:
|
|
1. Validates the YAML + interpolates `${VAR}` env references (fails fast if any are missing).
|
|
2. Auto-spawns a daemon on `127.0.0.1:8765` if none is reachable.
|
|
3. Sends `POST /v1/workspaces` and prints the returned detail as JSON.
|
|
|
|
## Run commands in a workspace
|
|
|
|
```bash
|
|
# synchronous, blocks until the command finishes
|
|
mirage execute -w <workspace-id> -c "ls /"
|
|
|
|
# background, returns a job id immediately; poll/wait later
|
|
mirage execute --bg -w <workspace-id> -c "wc -l /large.csv"
|
|
mirage job wait <job-id>
|
|
```
|
|
|
|
## Workspace lifecycle
|
|
|
|
| Command | Purpose |
|
|
|---|---|
|
|
| `mirage workspace create <config.yaml>` | Create; auto-spawns daemon if needed. |
|
|
| `mirage workspace list` | List active workspaces. |
|
|
| `mirage workspace get <id> [--verbose]` | Show one workspace's detail. |
|
|
| `mirage workspace delete <id>` | Stop and remove. |
|
|
| `mirage workspace clone <src> [--id NEW] [--at REF]` | New workspace from the source; `--at REF` clones a past version, else the live state. |
|
|
| `mirage workspace snapshot <id> <out.tar>` | Snapshot to tar. |
|
|
|
|
## Versioning
|
|
|
|
Each workspace has a git-backed history kept by the daemon (under
|
|
`~/.mirage/repos/<id>`; set `MIRAGE_VERSION_ROOT` to relocate). Same verbs and
|
|
semantics as the [Python CLI](/home/cli#versioning).
|
|
|
|
```bash
|
|
mirage workspace commit <id> -m "first" # commit live state
|
|
mirage workspace log <id> [-b branch] # versions, newest first
|
|
mirage workspace diff <id> [a] [b] # changed paths; no refs = live vs HEAD
|
|
mirage workspace branch <id> <name> [--from b] # fork a branch
|
|
mirage workspace checkout <id> <ref> # restore in place (version id or branch)
|
|
mirage workspace clone <src> --at <ref> --id new # new workspace from a past version
|
|
```
|
|
|
|
| Command | Purpose |
|
|
|---|---|
|
|
| `mirage workspace commit <id> [-m MSG] [-b BRANCH]` | Commit the live state as a version. |
|
|
| `mirage workspace log <id> [-b BRANCH]` | List versions on a branch, newest first. |
|
|
| `mirage workspace diff <id> [a] [b] [-b BRANCH]` | Changed paths (added/modified/deleted). |
|
|
| `mirage workspace branch <id> <name> [--from BRANCH]` | Fork a branch at a branch's current version. |
|
|
| `mirage workspace checkout <id> <ref>` | Restore the live state in place to a version or branch. |
|
|
|
|
## Sessions
|
|
|
|
```bash
|
|
mirage session create <workspace-id> --id agent_a
|
|
mirage session list <workspace-id>
|
|
mirage session delete <workspace-id> <session-id>
|
|
```
|
|
|
|
## Daemon lifecycle
|
|
|
|
```bash
|
|
mirage daemon status # health + PID + uptime
|
|
mirage daemon stop # graceful shutdown (POST /v1/shutdown + SIGTERM fallback)
|
|
mirage daemon restart # stop; next CLI command auto-spawns fresh
|
|
mirage daemon kill # SIGKILL; last resort
|
|
```
|
|
|
|
## Configuration
|
|
|
|
Precedence (highest first):
|
|
|
|
1. **`MIRAGE_DAEMON_URL`** env var, e.g. `http://127.0.0.1:9000`.
|
|
2. **`MIRAGE_TOKEN`** env var, bearer token passed as `Authorization: Bearer <token>`.
|
|
3. **`~/.mirage/config.toml`** `[daemon]` table, managed with
|
|
`mirage config list|get|set|unset` (per key: env var >
|
|
`config.toml` > default; `mirage config list --resolved` shows the
|
|
effective values and origins):
|
|
```toml
|
|
[daemon]
|
|
url = "http://127.0.0.1:8765"
|
|
auth_token = ""
|
|
idle_grace_seconds = 30
|
|
port = 8765
|
|
version_root = "/data/repos"
|
|
```
|
|
The daemon validates the table at startup and refuses to start on
|
|
unknown keys or malformed TOML. The full key list and semantics
|
|
match the Python CLI docs.
|
|
|
|
## Python parity
|
|
|
|
The daemon speaks the same `/v1/...` protocol as Python's `mirage` CLI. A Python CLI client can talk to a Node daemon and vice versa. The CLI subcommand tree matches Python's `mirage/cli/*.py` file-for-file.
|
|
|
|
## Where things live
|
|
|
|
| File | Purpose |
|
|
|---|---|
|
|
| [`packages/server/src/app.ts`](https://github.com/strukto-ai/mirage/blob/main/typescript/packages/server/src/app.ts) | Fastify app factory. |
|
|
| [`packages/server/src/routers/`](https://github.com/strukto-ai/mirage/tree/main/typescript/packages/server/src/routers) | health / workspaces / sessions / execute / jobs. |
|
|
| [`packages/server/src/bin/daemon.ts`](https://github.com/strukto-ai/mirage/blob/main/typescript/packages/server/src/bin/daemon.ts) | `mirage-daemon` bin. |
|
|
| [`packages/cli/src/main.ts`](https://github.com/strukto-ai/mirage/blob/main/typescript/packages/cli/src/main.ts) | CLI program wiring. |
|
|
| [`packages/cli/src/{workspace,session,execute,provision,job,daemon}.ts`](https://github.com/strukto-ai/mirage/tree/main/typescript/packages/cli/src) | Per-subcommand modules. |
|
|
| [`packages/cli/src/client.ts`](https://github.com/strukto-ai/mirage/blob/main/typescript/packages/cli/src/client.ts) | HTTP client + auto-spawn. |
|