1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//! Command-line interface definition.
use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
/// A Laravel-inspired Rust framework for MCP-first apps.
#[derive(Debug, Parser)]
#[command(name = "slave", version, about, long_about = None)]
#[command(propagate_version = true, arg_required_else_help = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Create a new slave application
New(NewArgs),
/// Create a new model in a domain module
///
/// Writes src/modules/<module>/model.rs. The module defaults to the model
/// name in snake_case (`BlogPost` → `blog_post`) and is created if missing.
#[command(name = "make:model")]
MakeModel(MakeArgs),
/// Create MCP tools for a domain module
///
/// Writes src/modules/<module>/tools.rs with example `<name>_list` and
/// `<name>_get` tools and registers it in src/modules/mod.rs. MCP tools are
/// the application's only business interface. The module defaults to the
/// name without its `Tools` suffix, in snake_case (`BlogPostTools` →
/// `blog_post`).
#[command(name = "make:tools")]
MakeTools(MakeArgs),
/// Create a web app in apps/<name>
///
/// Without --domain or --path the app is reached directly on its port.
/// With them, that domain and/or path is routed to it. The runtime serves
/// it in-process, or proxies to it with --separate.
///
/// `--stack minijinja` (default), `tera`, `handlebars` or `liquid` render
/// pages on the server from templates in `apps/<name>/templates/` with that
/// engine (e.g. a storefront theme); such apps are registered in
/// config/apps.toml and started by `slave serve`. The app gets its data from
/// the MCP backend.
#[command(name = "make:app")]
MakeApp(MakeAppArgs),
/// Create an empty SurrealQL migration
///
/// Writes database/migrations/<timestamp>_<name>.surql; fill it with
/// DEFINE TABLE / FIELD / INDEX statements (or data changes) and apply it
/// with `slave migrate`. Each migration runs in one transaction.
#[command(name = "make:migration")]
MakeMigration {
/// Migration name in snake_case, e.g. `add_phone_to_users`
name: String,
},
/// Apply every pending migration to the database in SURREAL_*
Migrate,
/// List migrations and whether each is applied
#[command(name = "migrate:status")]
MigrateStatus,
/// Drop every table in the database, then apply all migrations
///
/// Destroys all data in the SURREAL_* database; asks you to confirm
/// unless --force.
#[command(name = "migrate:fresh")]
MigrateFresh {
/// Do not ask for confirmation
#[arg(long)]
force: bool,
},
/// Add Fly.io deployment files for the single runtime
///
/// Writes Dockerfile, .dockerignore, fly.toml and config/apps.fly.toml
/// (config/apps.toml with `localhost` hosts moved under --domain).
#[command(name = "install:fly")]
InstallFly(InstallFlyArgs),
/// Deploy the single runtime to Fly.io
///
/// Writes the Fly.io files if missing, creates the app when needed,
/// stages secrets from --secrets (SURREAL_*, SMTP_URL, ...), checks the
/// required ones are set, then runs `fly deploy` (migrations run as the
/// release command).
#[command(name = "deploy:fly")]
DeployFly(DeployFlyArgs),
/// List the domain routes in config/apps.toml and whether each app is up
#[command(name = "route:list")]
RouteList,
/// Show which route, app and headers a request would get
#[command(name = "route:match")]
RouteMatch {
/// Host and optional path to look up, e.g. `tokox.localhost` or `localhost/admin/users`
target: String,
},
/// Compile the backend, the runtime and the separate apps, or only some
///
/// With no names, everything is built. Name components to build only
/// those (e.g. in CI, only what changed): `backend`, `runtime`, or a
/// separate app (`embed = false`). `--list` shows them with the paths that
/// affect each.
Build(BuildArgs),
/// Run what `slave build` compiled: the runtime, plus each separate app
Serve(ServeArgs),
/// Check the setup: database, sign-in email and passkeys, the build
///
/// Prints what is missing and how to fix it. Fails if anything is missing.
Doctor,
/// Run an app as a process of its own, proxied by the runtime
///
/// Sets `embed = false` on its entries in config/apps.toml and removes it
/// from runtime/ (so the runtime no longer compiles it).
#[command(name = "app:separate")]
AppSeparate {
/// The app, as in apps/<name>
name: String,
},
/// Serve a separate app in-process again, inside the runtime
#[command(name = "app:embed")]
AppEmbed {
/// The app, as in apps/<name>
name: String,
},
}
#[derive(Debug, Args)]
pub struct NewArgs {
/// Name of the application (also used as the directory and package name)
pub name: String,
/// Depend on a local checkout of slave-framework instead of crates.io
#[arg(long, value_name = "PATH")]
pub framework_path: Option<PathBuf>,
}
#[derive(Debug, Args)]
pub struct MakeArgs {
/// Type name in PascalCase, e.g. `Post` or `PostTools`
pub name: String,
/// Domain module to generate into, in snake_case (default: derived from the name)
#[arg(short, long, visible_alias = "domain", value_name = "MODULE")]
pub module: Option<String>,
/// Overwrite the file with a fresh template if it already exists
#[arg(short, long)]
pub force: bool,
}
#[derive(Debug, Args)]
pub struct MakeAppArgs {
/// App name, used as apps/<name> and its package name, e.g. `dashboard`
pub name: String,
/// Host routed to the app, e.g. `admin.localhost` or `{toko}.localhost`
#[arg(long, value_name = "HOST")]
pub domain: Option<String>,
/// Path prefix routed to the app, e.g. `/admin`, on any host unless
/// --domain is given
#[arg(long, value_name = "PREFIX")]
pub path: Option<String>,
/// Port the app listens on [default: the next free port from 4000]
#[arg(long)]
pub port: Option<u16>,
/// Run it as a process of its own (`embed = false`), proxied by the
/// runtime, instead of inside the runtime
#[arg(long)]
pub separate: bool,
/// A customer-facing app (a storefront): its sessions reach only the
/// tools meant for customers, and signing in joins the store
#[arg(long)]
pub customer: bool,
/// The template engine the app renders its pages with
#[arg(long, value_enum, default_value_t = Stack::Minijinja)]
pub stack: Stack,
}
/// The kind of app `make:app` creates.
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum Stack {
/// Server-rendered pages with MiniJinja templates (Jinja2 syntax): light, fast to build
Minijinja,
/// Server-rendered pages with Tera templates (Jinja2/Django-like syntax)
Tera,
/// Server-rendered pages with Handlebars templates (`{{value}}`, partials)
Handlebars,
/// Server-rendered pages with Liquid templates (Shopify's theme language)
Liquid,
}
#[derive(Debug, Args)]
pub struct BuildArgs {
/// Components to build: `backend`, `runtime` or separate apps [default: all]
pub components: Vec<String>,
/// Build optimized binaries (for production or measuring performance)
#[arg(long)]
pub release: bool,
/// List the components and the paths that affect each, then exit
#[arg(long, conflicts_with = "components")]
pub list: bool,
}
#[derive(Debug, Args)]
pub struct ServeArgs {
/// Host address for the MCP backend [default: APP_HOST from the environment or .env, else 127.0.0.1]
#[arg(long)]
pub host: Option<String>,
/// Port for the MCP backend [default: APP_PORT from the environment or .env, else 3000]
#[arg(short, long)]
pub port: Option<u16>,
/// Run the release build (`slave build --release`)
#[arg(long)]
pub release: bool,
}
#[derive(Debug, Default, Args)]
pub struct InstallFlyArgs {
/// Fly app name [default: the project name]
#[arg(long)]
pub app: Option<String>,
/// Fly region for the machines [default: sin]
#[arg(long)]
pub region: Option<String>,
/// Public domain that replaces `localhost` in the routes, e.g.
/// `example.com` [default: <app>.fly.dev]
#[arg(long)]
pub domain: Option<String>,
/// Overwrite existing files
#[arg(short, long)]
pub force: bool,
}
#[derive(Debug, Args)]
pub struct DeployFlyArgs {
/// Env file whose settings become Fly secrets (SURREAL_*, SMTP_URL, MAIL_FROM, ...)
#[arg(long, value_name = "FILE")]
pub secrets: Option<PathBuf>,
}