VII · Digging Deeper
Console
On this page
Introduction
marmeon is the app's command line. It starts the development server, builds and starts the app, runs migrations and
workers, writes new files from templates, and runs the commands your modules add. Run it in the app's directory:
pnpm marmeon list
pnpm marmeon route:list
pnpm marmeon make:controller ShowNote --module=notes --viewmarmeon list, or marmeon alone, prints every command the app has, grouped by the part before the colon. The list grows with
the app: every installed package adds its commands, and so does every module that lists some. With npm, run the commands as
npx marmeon ….
Running commands
The marmeon package is a dependency of the app, not a dev dependency. marmeon start, migrate, queue:work and
schedule:work run on the server, and a production install leaves dev dependencies out.
Most commands boot the app first: they load .env, check the configuration and register every provider, just as the server
does. A command that cannot boot the app prints the error and the known solutions, and exits with 1:
✗ [marmeon:K6] Invalid configuration — the application cannot start:
• encryption: APP_KEY — Missing — run "marmeon key:generate"
Set or rename these variables in the environment or in .env (see .env.example).
ℹ How to fix it: Generate an application key
APP_KEY encrypts the cookies …
$ marmeon key:generateThe make:* generators of the framework itself (make:module, make:controller …), build, discover, key:generate,
make:lint-config and make:docker work without booting, so they run before the app has a valid .env. add installs without booting,
but for a package with migrations it runs publish, which boots the app: that needs a valid .env. The generators of
packages (make:auth, publish, make:*-table) boot the app. route:types and make:command register the app's providers without booting them, as the
build does, and need no secret either.
A command's options are checked before it runs. An unknown option, an option without its value or a value an option does not take (--force=x) is an error that prints
the command's usage line and exits with 2.
marmeon <command> --help (or -h) prints the command's description, its usage line and its options, and runs nothing; after a
--, --help is an argument like any other. marmeon list shows each command with its description. An unknown command says so
and exits with 2.
--no-interaction is an option of every command: it takes no value and is not among the command's options, and a command cannot
declare an option of that name. It stops a command from asking a question, as asking a question explains. Place
it after the command name and before a --; after a -- it is an argument. A command run with spawn() inherits it through the
environment variable MARMEON_NO_INTERACTION=1, which marmeon sets for the child; setting it yourself has the same effect as the option.
The environment comes from NODE_ENV in the shell, then from the app's .env. marmeon dev is development without one and
marmeon start and marmeon build production. Every other command takes what it finds, and without a NODE_ENV it behaves like
production: migrate then asks for --force. A NODE_ENV other than development, test or production stops every command
before it runs. The configuration page explains the rules.
Exit codes
| Code | Meaning |
|---|---|
0 | The command succeeded. |
1 | The command ran and failed: the app could not start, or the command reported an error or threw. |
2 | marmeon was called wrongly: an unknown command, an unknown option, an option without its value, a value an option does not take, or an argument the command itself refuses (a name that is no PascalCase, --workers=abc, schedule:test without a task). |
130 | The person cancelled a question the command asked (Ctrl-C). |
When the app fails to load, the message ends with the place in the app where it happened, as at modules/shop/routes.ts:12:3, relative to the app: the first line of your own code on the error's stack or, for a syntax error Node finds in a .ts file, that file. An error inside a package names the line of your code that called it, and no file when none of your code is on the stack. For some syntax errors Node reports only the message, such as a duplicate export or an invisible character in a regular expression: marmeon then parses that one file once more with Node's own parser, without running it, and names its line and, where V8 gives one, its column. It names the file alone when that parse does not give the same error, and none when it cannot tell which file that was, as for a module that awaits an import() of its own.
What marmeon prints about a failed command or a failed start, including the hints on how to fix it, is masked with the app's redactor (the core's lists and the redact additions of the app), as the messages of marmeon check are. Its control characters are written out, and the lines after the first of a command's error are indented. Three cases mask with the core's lists alone: an app whose definition cannot be read, a wrong option to a built-in command (found before the app starts; those messages quote no values), and the error of a built-in that does not start the app (make:*, key:generate, build). marmeon does not read the app's definition only to mask these.
marmeon check and marmeon doctor add a 3 for a check that could not run.
A command that ends with an error (exit code 1 because it threw) is also handed to the app's error reporters
(source command), with the command's name and never its arguments, which can carry secrets. A wrong call (2), a cancelled question
(130) and a command that returns an exit code without an error are not reported.
When the reader of a pipe stops early, as in marmeon docs | head -5, the command stops writing and ends with its own exit code, without an error. Any other failure to write stdout still fails the command.
A script can tell a typo from a failure this way. A built-in's options are checked before the app boots; an app's own command is looked
up once the app has booted, so a failed boot (1) comes first. A few commands have codes of their own: docs ends with 2 for an unknown page or options that do not go together, tinker ends with
130 on a signal, db:query with 3 when it refuses the query (a write, a secret column, or a record of migrations that cannot say which columns are secret), and queue:work with 70 when a job does not stop in time. A command that checks its own arguments, such as schedule:test without a name, exits with 2 as well: it throws a CommandArgumentsError, and marmeon prints its message and exits with 2. The state of the app or of the machine is a failure (1), whatever the arguments:
| Wrong call (2) | Failure (1) |
|---|---|
make:event without a name, or with a name that is no PascalCase; make:controller without --module | make:event --module=billing when the module does not exist; a file the generator would write exists and --force is missing |
make:docker --caddy --nginx | make:docker when its files exist, without --force |
start --workers=abc, schedule:work --stop-timeout=x, queue:work --sleep=x | A server that cannot start, a job that fails |
schedule:test without a task name or with an unknown one | schedule:test of a task that fails |
migrate --wait=soon, publish with two packages, uploads:prune --hours=soon | migrate that cannot take the lock |
auth:end-sessions without an identifier | auth:end-sessions <identifier> without --force, migrate:fresh without --force on a protected environment, uploads:prune --hours=0 without --force: the arguments are well formed, the state decides |
Machine-readable output
A command that takes --json prints one JSON document instead of its text, for scripts and tools:
pnpm marmeon route:list --json- The first key of the document is
format, a whole number: the version of that command's document. Each command counts on its own, soroute:listformat 1 and another command's format 1 are different formats. - A new field is no new version. Removing or renaming a field, or changing its type or meaning, is a new
formatand a breaking change.--jsonalways prints the newest format. - stdout holds the document and nothing else; warnings are in its
warningslist. With--jsonthe app's logger (@marmeon/logand the console logger) writes every line, whatever its level, to stderr, and so does whateverconsole.logorprocess.stdout.writewrites meanwhile. Writes straight to the file descriptor (fs.writeSync(1, …), a logger withdestination(1)) still reach stdout. A missing value isnull, never left out. - When the command fails (exit code other than 0), stdout stays empty and the message is on stderr, as without
--json. Parse stdout only after exit code 0.
| Command | Document |
|---|---|
route:list --json | Listing routes |
check --json | Checking an app |
doctor --json | The environment |
schedule:list --json | Running the scheduler |
db:show --json | Inspecting a connection |
db:query --json | Querying a connection |
migrate:status --json | Status |
modules:list --json | Listing the modules |
devtools:list --json | Listing the entries |
docs --json | Reading the documentation |
upgrade --json | How to upgrade |
list --json | The commands marmeon list shows. complete is false when the app did not load and only the built-in commands are known. Each command has name, description, usage, options (name, type, short, multiple, default), experimental and launcher (dev and start, which the launcher runs). |
A command of your own, or of a package, prints its document with output.json({ format: 1, … }) and declares
static options = { json: { type: 'boolean' } }.
The development server
marmeon dev, which pnpm dev runs, serves the app with Vite in front of it and starts what the app needs next to it. The
installation page shows it from the outside. Under the hood:
- Server code is watched by Node: a change to a route, a controller or a provider restarts the server. A change to a page reaches the browser at once, without a restart.
- Migrations are watched as well: a file you add, change or remove under a module's
migrations/is read again without a restart, and the app answersmarmeon migraterun in another terminal within a second (while you develop). The queue worker and the scheduler keep the schema they started with until the server restarts them. - A queue worker on every queue starts next to the server, unless the default queue connection is
sync. - The scheduler starts when a module schedules tasks.
bootstrap/routes.tsis written on every start, and again when a view is added or removed. Route names and views are then known to the type checker without runningroute:typesyourself.- A warning names every class under
modules/with a literalstatic joborstatic notificationthat no module lists. The files are only read, never run, and the registration stays explicit.marmeon buildprints the same warning.
The worker and the scheduler stop and start with the server, so a code change reaches them too. One that ends on its own is
started again a second later. One that ends right after its start, say with a configuration error, stays down until you save a
file. A server that is killed or crashes takes them along: they stop as on SIGTERM, and none is left running beside the next one.
marmeon dev sets NODE_ENV=development when neither the shell nor .env sets it. With another NODE_ENV, from either, it
says so and serves the build instead, without Vite, the devtools, the worker and the scheduler. --workers belongs to marmeon start, and marmeon dev refuses it.
marmeon build and marmeon start are covered on the deployment page, --workers under
several processes on one machine and make:docker under
the Docker image.
Built-in commands
| Command | What it does |
|---|---|
dev | The development server, with a worker and the scheduler next to it. |
build [--no-typecheck] | Builds the app for production. See deployment. |
check [--only=<names>] [--skip=<names>] [--json] | Runs the type check, the lint, the scan for imports of framework internals and the checks of the app (route and database types, boot, readiness), and exits with a code a script can read. See checking an app. |
doctor [--only=<names>] [--skip=<names>] [--json] | Checks that this machine can run the app: Node, the versions of the packages, the configuration and APP_KEY, the generated files, the migrations that have not run and the services, with the report and exit codes of check. See the environment. |
upgrade [--to=<version|tag>] [--dry-run] [--json] | Moves every marmeon and @marmeon/* package of the app to one version (latest, or --to), prints the entries of the upgrade guide between the two versions, and runs route:types, and db:types when the app has @marmeon/database. --dry-run only prints the plan. See how to upgrade. |
serve [--workers=N] | The command behind dev and start; hidden from marmeon list, but its name and options are API. Run marmeon start rather than it. |
start [--workers=N] | Starts the production server on the build. It refuses to run when NODE_ENV=development or test comes from .env alone: use marmeon dev, set NODE_ENV=production to try the build, or set NODE_ENV=development in the shell to start the development stack on purpose. |
route:list [--json] | Every route with its method, path, name, group, middleware, who may call it (ACCESS) and action, with (island) after an island's controller. See listing routes. |
route:types [--check] | Writes bootstrap/routes.ts. --check fails when it is out of date, for CI. It also exits with 1 and lists every route that does not say who may call it, so marmeon build stops on one. See typed route names and every route decides. |
modules:list [--json] | The packages, the modules with their providers, commands, jobs, notifications and seeders, and the listeners of each event, without booting the app. See listing the modules. |
discover | Finds the installed packages and their providers. See discovery. |
add <package>... [--dry-run] | Installs framework packages at exactly the version of your app, runs discover and copies the migrations of a package that has some (publish boots the app, so that part needs a valid .env). --dry-run prints the commands and changes nothing. See packages you add. |
key:generate [--show] [--force] | Sets APP_KEY in .env. |
agents:sync [--check] | Writes AGENTS.md and CLAUDE.md, or brings the block of marmeon in AGENTS.md up to the installed version. --check writes nothing and fails when the block is missing or out of date, for CI. See coding agents. |
agents:install [--shared] [--no-mcp] [--check] | Copies the skills of marmeon into .claude/skills/ (.agents/skills/ with --shared) and enters marmeon mcp in .mcp.json; run again, it updates them. Refuses links that lead out of the app or nowhere, and files that are not its own. --check writes nothing and fails when they are missing or out of date. See coding agents. |
mcp | Serves the routes and the last error of the app to a coding agent over MCP, on standard input and output. Only with NODE_ENV=development; it has no network transport. See the MCP server. |
docs [<page>] [--path] [--json] | Lists the pages of the documentation that came with the installed marmeon, or prints one. See reading the documentation. |
tinker [--sandbox] [--execute "<code>"] [--no-history] | A REPL with the booted app. See tinker. |
make:lint-config [--boundaries] [--force] | Writes the lint preset. See lint. |
make:docker [--caddy | --nginx] [--systemd] [--force] | Writes the files for a production image. See deployment. |
package:build [dirs…] [--clean] | Builds framework packages for publishing. See package development. |
key:generate copies .env.example to .env when there is no .env yet, then writes a new key. --show only prints a key. An
app that has a key keeps it unless you pass --force, which moves the old key to the front of APP_PREVIOUS_KEYS: sessions,
encrypted cookies and signed links made with it stay valid. The deployment page explains the
rotation on a server.
Reading the documentation
marmeon docs reads the documentation of the installed version, the files marmeon ships,
and runs without booting the app, so it works in an app that does not start. It needs nothing from the network.
pnpm marmeon docs # every section and page: slug, title, file
pnpm marmeon docs routing # the page on stdout, unchanged
pnpm marmeon docs routing --path # only the absolute path of the file
pnpm marmeon docs --json # the list for a program<page>is a slug from the list.routing,routing.mdandrouting#anchorname the same page; the anchor is ignored and the whole file printed.- The command prints only pages that
docs/index.jsonlists. What you type is looked up there and never used as a path, so../package, an absolute path or a symlink is not a page: an unknown page ends with exit code 2 and up to five similar slugs. --pathneeds a page, and--jsontakes none (exit code 2). There is no search;grepover the paths in the list does it.- A
marmeonwithout the documentation, as in the repository beforepnpm build, or with anindex.jsonof another format ends with exit code 1 and says so.
docs --json prints format 1: format, version (of marmeon), root (the absolute path of the package; root and a page's file make its path), sections (each with title and pages, whose entries have slug, title and file) and warnings. The pages are in reading order.
Generators
The make:* commands write a file into a module from a template. make:module adds the module to bootstrap/app.ts. make:listener, make:job, make:notification, make:command, make:seeder and make:migration
also add the class (or the migrations folder) to the module's index.ts, where the module lists such things. When index.ts has another shape (a list kept in a variable, say),
they leave it as it is and print the lines to add; --no-register always prints them. The commands run without booting the
app (make:command registers it the way marmeon build does, no .env needed, to see every command name), and never overwrite a file unless you pass --force:
| Command | Writes |
|---|---|
make:module <name> [--no-routes] [--no-register] | modules/<name>/index.ts and routes.ts (--no-routes writes index.ts without routes, for a module that has none); adds the module last in modules of bootstrap/app.ts, then runs db:types in an app with @marmeon/database. |
make:controller <Name> --module=<m> [--view] [--request] | A controller. --view adds its page, --request a query or body schema. See controllers. |
make:event <Name> --module=<m> | An event class in events/. See events. |
make:listener <Name> --event=<Event> --module=<m> [--queued] [--no-register] | A listener in listeners/, added to the module's listeners with its event. It writes nothing and exits with 1 when the event is neither in the module's events/ nor imported by its index.ts. --queued writes a queued listener with static queue and a stable static listener (<m>.<name>). See events. |
make:job <Name> --module=<m> [--no-register] | A queued job in jobs/, added to the module's jobs. See queues. |
make:notification <Name> --module=<m> [--no-register] | A notification in notifications/, added to the module's notifications. See notifications. |
make:mail <Name> --module=<m> [--layout=<m>] [--template | --html] | A mail in mail/ (Mail is added to the name) with envelope(), content() and a static preview(). In an app with @marmeon/react it adds a React view <Name>View.tsx and the frame mail/Layout.tsx when the module has none; without it, or with --template, the mail holds an mjml template inside mail/layout.ts. --html writes html`…` and no frame, and fails with --layout or --template. --layout=<m> imports the frame that module exports (Layout, or layout for a template) and writes none; the module must exist and have a frame (see one frame). A mail is found by its folder, so nothing is registered. Needs @marmeon/mail and @marmeon/i18n in the app's dependencies, and oxc-transform for a view (a warning says so). See writing mails. |
make:command <Name> --module=<m> [--command=<name>] [--no-register] | A console command in commands/ named <m>:<name>, or --command when you pass the name to type (kebab-case, a colon before a group; checked against the same registry), added to the module's commands. See writing commands. |
make:seeder <Name> --module=<m> [--no-register] | A seeder in seeders/, added last to the module's seeders. See seeding. |
make:middleware <Name> --module=<m> | A middleware class in middleware/. |
make:policy <Name> --module=<m> [--ability=<name>] | A policy in policies/ that allows the owner of a record (user_id) and answers everyone else with a 404, or with --ability one ability without a record that answers false until you decide. Needs @marmeon/auth in the app's dependencies. See generating a policy. |
make:test <name> --module=<m> [--path=/…] | modules/<m>/<name>.test.ts: a test that boots the app and expects --path (default /<m>) to answer 200. It fails until the route exists — change it to what you test. See creating the test app. |
make:resource <Name> [--module=<m>] [--no-register] | A new module for a record of the signed-in user: migration, repository, policy, the six controllers with their requests, two pages and a test, added to bootstrap/app.ts. Needs the auth module of the starter kit. It never changes an existing module. See adding a resource. |
make:repository <Name> --module=<m> [--table=<t>] | modules/<m>/<Name>Repository.ts: a Repository<'<t>'> with its static table, the table being the plural of the name in snake case (InvoiceLine is invoice_lines) unless --table names it. Registers nothing: the container builds the class. Needs @marmeon/database. See defining a repository. |
make:factory <Name> --module=<m> [--table=<t>] | modules/<m>/factories/<Name>Factory.ts: a defineFactory of the table, with a note on sequence and now(). Registers nothing: a factory is imported where a test or seeder uses it. Needs @marmeon/database. See defining factories. |
make:table <Name> --module=<m> [--table=<t>] | modules/<m>/tables/<Name>Table.ts: a defineTable of the table, typed with the module's Database, with its key, an id column and authorize: () => false, so nobody sees it until you say who may. Registers nothing: the page's route attaches <Name>Table.endpoints(). Needs @marmeon/table, @marmeon/auth and @marmeon/database. See data tables. |
make:migration <snake_case_name> --module=<m> [--no-register] | A timestamped migration in migrations/; adds the folder to the module once. See migrations. |
publish [<package>] [--module=<m>] [--only=migrations,lang] [--check] [--accept] [--force] | The migrations a direct dependency of your app lists, into a module of the app; writes what is missing and skips what is there, and records them in marmeon-stubs.json. Without a package it lists them and, at a terminal, asks which to publish. --check writes nothing and ends with exit code 1 when something is missing, when a migration changed in the package since you published it (D27), or, once a direct dependency declares migrations, when marmeon-stubs.json cannot be read. Without a package, publish ends with exit code 1 on a changed migration instead of saying "Nothing to publish". --accept takes one package, writes no migration and records the package's current files for the migrations your app has. --only=lang copies the framework's texts of @marmeon/i18n into lang/marmeon/, and --force replaces files that are there. See migrations and the framework's texts. |
make:sign-ins-table [--module=<m>] | The migration of the sign_ins table that DatabaseSignIns uses: publish for @marmeon/auth. See sign-ins. |
make:social-accounts-table [--module=<m>] | The migration of the social_accounts table that the linked provider accounts use: publish for @marmeon/oauth, which marmeon add oauth runs. make:social-accounts-table also works when the app links the package. Both skip a migration the app has. publish opens an existing system module only for a package from the registry. publish records the migration in marmeon-stubs.json; make:social-accounts-table does not. See social login. |
make:cache-table, make:session-table, make:queue-table, make:notifications-table, make:uploads-table, make:live-table [--module=<m>] | The migrations of the database drivers' tables, each publish for its own package: writes what your app lacks, and ends with exit code 0 and "Nothing to publish" when it has it all. See the framework's tables. |
A generator never writes through a link that leads out of the project, and neither do route:types and db:types with bootstrap/routes.ts and bootstrap/database.d.ts: they stop with an error and write nothing. A link or hard link at either of those two files is refused too, even inside the project: replace it with a regular file. When a file it would create is a link to nothing, it refuses. With --force, it refuses to overwrite a generated file that is a link or has other hard links. Adding a module to bootstrap/app.ts edits that file where it really lies, as long as that is inside the project.
--module names a module that exists: make:module comes first. -m is short for it.
make:controller decides nothing about who may call the controller: say it in the request's authorize, or with Route.authorize(…) on the registrar (everyone if anyone may). The command prints that reminder after the route line. In a module made with --no-routes it prints the routes.ts to create and the routes entry for defineModule instead, and writes neither.
Several modules at once: run make:module <name> --no-register for each, list them in bootstrap/app.ts in the order you want (routes match in module order), and run marmeon db:types once.
make:controller --request writes a request with an empty schema (r.object({}), or r.query({}) for a reading name) with an example field as a commented line: add your own fields there.
Commands of the packages
The installed packages add their commands when the app boots:
| Package | Commands |
|---|---|
@marmeon/database | migrate, migrate:rollback, migrate:reset, migrate:fresh, migrate:status, publish, db:seed, db:show, db:query (NODE_ENV development and test only), db:types. The four that change the schema take --wait=<seconds> (default 60) for another migration to end, see one migration at a time. See migrations and seeding. |
@marmeon/queue | queue:work, queue:size, queue:failed, queue:retry, queue:forget, queue:flush, queue:prune-failed, make:queue-table. See queues. |
@marmeon/scheduler | schedule:work, schedule:run, schedule:list, schedule:test. See task scheduling. |
@marmeon/cache | cache:prune, cache:clear, make:cache-table. See cache. |
@marmeon/session | session:prune, make:session-table. See session. |
@marmeon/storage | uploads:prune, make:uploads-table. See file storage. |
@marmeon/live | make:live-table. See real-time updates. |
@marmeon/notifications | notifications:prune, make:notifications-table. See notifications. |
@marmeon/auth | make:auth, make:sign-ins-table, auth:end-all-sessions --force [--guard=web] [--keep-api-tokens] [--keep-reset-tokens] (signs every account out and revokes API and reset tokens, see ending every session of every account), auth:prune-tokens [--guard=<name>] (also deletes the sign-ins that are over, see sign-ins), auth:end-sessions <identifier> --force [--guard=<name>] [--keep-api-tokens] (see ending every session of a user) and auth:reset-two-factor <identifier> --force [--guard=<name>] (see operator reset). --guard names a package's guard, see operator commands for a guard. The module make:auth writes adds auth:prune-unverified. See starter kit. |
@marmeon/oauth | make:oauth, make:social-accounts-table. See social login and storing tokens. |
@marmeon/devtools | devtools:clear, devtools:list, devtools:prune. See devtools. |
Writing commands
A command is a class with a name, a description and handle(). It is built through the container like a controller, so its
constructor gets what it asks for:
import { Clock } from '@marmeon/core';
import { CommandArgumentsError, type CommandInput } from 'marmeon';
import { NoteRepository } from '../NoteRepository.ts';
const DAY = 86_400_000;
export class PruneArchivedNotesCommand {
static command = 'notes:prune-archived';
static description = 'Delete notes archived more than --days ago';
static usage = '[--days=30]';
static options = { days: { type: 'string' } } as const;
readonly #notes: NoteRepository;
readonly #clock: Clock;
constructor(notes: NoteRepository, clock: Clock) {
this.#notes = notes;
this.#clock = clock;
}
async handle({ options, output }: CommandInput): Promise<number> {
const days = Number(options.days ?? 30);
if (!Number.isInteger(days) || days < 1) {
throw new CommandArgumentsError(`--days must be a whole number of days, not ${String(options.days)}.`);
}
const deleted = await this.#notes.deleteArchivedBefore(new Date(this.#clock.now() - days * DAY));
output.success(`Deleted ${deleted} archived notes.`);
return 0;
}
}marmeon make:command PruneArchivedNotes --module=notes writes the class with the name notes:prune-archived-notes and lists it in
the module. The generator refuses, and writes nothing, when the name is taken — by a built-in, an installed package or a module. It loads the app the way marmeon build does, every provider registered and none booted, so an app that cannot be loaded stops it with that error. A module lists its commands, and they appear in marmeon list:
import { defineModule } from '@marmeon/core';
import { PruneArchivedNotesCommand } from './commands/PruneArchivedNotesCommand.ts';
import routes from './routes.ts';
export default defineModule({
name: 'notes',
routes,
commands: [PruneArchivedNotesCommand],
});static commandis the name you type.make:command --command=notes:prunesets it instead of<module>:<class name>, with the same check against the commands the app has. A part before a colon groups it in the list. A name used twice by different commands — two modules, a module and a package, or a module and a built-in — failsmarmeon buildand the start with an error naming both classes and where they come from (a built-in that runs without booting, such asmake:*orkey:generate, still runs, butmarmeon build,marmeon listand every command that loads the app report the clash); the same class listed twice is fine.list,help,devandstartare marmeon's own (the last two are handled by the launcher before any command is looked up) and refused as command names with K8.static usageis shown in errors, after the name:Usage: marmeon notes:prune-archived [--days=30].static optionsdeclares the options in the format of Node'sparseArgs:{ type: 'string' }or{ type: 'boolean' }, withshort: 'd'for a one-letter form. An option the command does not declare is an error before the command runs.static hidden = truekeeps a command out ofmarmeon list. A hidden command is a step of another command, not API: its name and options may change in any release (serveis the exception). See what is public API.static experimental = truemarks a command that may change in any minor version.marmeon listand--helpadd "(experimental)". See experimental.handle(input)gets the positional arguments asargs, the options asoptions, the console asoutputand the app's directory asroot,promptfor asking a question, andspawn(...args)runs anothermarmeoncommand in a fresh process. It returns the exit code, and nothing means 0.
output writes line(), info(), success() and table(header, rows) to stdout, and warn() and error() to stderr. Colours
are dropped when the output is no terminal. Control characters in the text, such as an escape sequence in a file name the command prints, are written out (\u001b) so they cannot steer the terminal; line feeds, tabs and colours stay.
Each run gets a scope of its own, as a request does. A scoped service, such as the Translator, is fresh for each command and
speaks APP_LOCALE. The app shuts down after the command, so open connections never keep the process alive. An error the command
throws prints its message and the first lines of its stack, and the exit code is 1. To say that the arguments are wrong, throw a CommandArgumentsError (from marmeon) with the message: marmeon prints it without a stack, does not hand it to the error reporters and exits with 2.
The scheduler runs a command as a task: s.command('notes:prune-archived', ['--days=60']).daily(). Each run again gets a scope of
its own. The task scheduling page covers the schedule.
Asking a question
A command that has to know which of several things to do can ask through prompt. Ask only when prompt.interactive is true, and
take the answer from an option otherwise. prompt.choose(question, choices, { multiple }) numbers the choices from 1 and resolves with
the indexes of those picked:
async handle({ prompt, options, output }: CommandInput): Promise<number> {
const packages = ['@marmeon/auth', '@marmeon/queue', '@marmeon/storage'];
if (!prompt.interactive && options.package === undefined) {
output.error('Say which package with --package=<name>; nothing is asked here.');
return 2;
}
const picked = prompt.interactive ? await prompt.choose('Which packages?', packages, { multiple: true }) : [];
// …
return 0;
}The answer is one number, or with multiple several, separated by commas or spaces, or a for all. An empty answer picks none. An
answer that is no choice is asked again, up to three times, then counts as none. Control characters in the question and the choices
are dropped, so a name taken from a package cannot redraw the terminal. Ctrl-C or the end of the input ends the command with
"cancelled" and exit code 130; a command that wraps choose() in a try should let that error pass.
prompt.interactive is true only when stdin and stdout are both a terminal, the environment variable CI is unset (or empty, 0 or
false) and --no-interaction is not given. Without a terminal, in CI or with --no-interaction, nothing is asked: choose() throws
instead of waiting. An agent without a terminal is never asked. The scheduler runs commands without a terminal.
prompt and output are given to a command and are not meant to be implemented: a later release may add a member. A test runs the command with app.command() instead of building them.
Testing a command
A test runs a command by its name with app.command('queue:retry', { args: ['all'] }): the exit code and the printed lines come back, and nothing is asked. See running commands in the testing guide. The CommandInput a command's handle() is given is built by marmeon and app.command(), not by your code; a later release may add a member.
Tinker
marmeon tinker opens a REPL with the booted app. It is Node's own REPL: await works at the top level, input may span several
lines, and you type TypeScript with the same erasable syntax as the app's files:
$ pnpm marmeon tinker
Marmeon tinker · my-app · NODE_ENV=development · db sqlite (storage/database.sqlite) · .ls lists helpers
> const user = await repos.users.find(1)
> url('notes.index')
'/notes'
> await jobs.dispatch(SendWelcomeMailJob, { userId: user!.id })The TypeScript input relies on Node's module.stripTypeScriptTypes, which Node still calls experimental: the command, its flags, the exit codes and the sandbox are stable, but what the REPL accepts of TypeScript follows Node's type stripping.
| Helper | What it is |
|---|---|
app | The Application: its container, modules and root. |
make(Key), make('Name') | Resolves a class or token in the session's scope, also by its name. |
db | The query builder of the default connection. |
repos.<table> | The app's repositories, by their table, or by class name where two share a table. |
jobs | The Queue. |
events | The EventDispatcher. |
mail | The Mailer. |
url(name, params?, query?) | The path of a named route. |
t(key, params?) | A text in APP_LOCALE. |
config.<name> | The resolved configuration: config.app, config.mail, … It shows secrets as they are, the APP_KEY bytes and SMTP and Redis passwords included: mind the scrollback and the CI logs of tinker -e. |
Every class and token the container binds, every class a module lists, such as jobs, listeners and seeders, and every repository is
there by its name: make(Mailer) and jobs.dispatch(SendWelcomeMailJob, …) need no import. A helper is built on first use, and
one whose package the app lacks says what to install. A result that is a promise is awaited. Tab completes the helpers, the names,
repos., config. and route names in url('. .ls lists them all, .help the REPL's commands.
The session has one scope from start to end. The log carries no request context.
Trying things in a sandbox
--sandbox runs the whole session in one transaction on the default connection and rolls it back when the session ends: on
.exit, Ctrl-D, Ctrl-C twice, a signal or a crash. A session that dies never commits. Each input is a savepoint of its own, so a
failing input takes back only its own writes. So does an input whose value is an err, such as a tryInsert() of a taken
address: an err rolls its savepoint back, as the transactions page explains, and tinker
still prints it. Jobs on the database queue join the transaction and are gone with it, and jobs on other queues and mails that
wait for the commit never go out.
A sandbox does not undo a mail sent directly, a file written to a disk, a Redis command or an HTTP call. Nor does it undo what the cache, its locks and rate limits, and the sessions write: they use a connection of their own, also inside the sandbox. On SQLite, when they share the app's file, they cannot write inside the transaction at all. Tinker says so and suggests giving them a file of their own, which the cache page explains.
Running code from a script
--execute, or -e, evaluates one input and exits:
pnpm marmeon tinker --execute "await repos.users.count()"
pnpm marmeon tinker --sandbox -e "await repos.notes.insert({ user_id: 1, title: 'Draft', body: '' })"Only the value goes to stdout: a string as it is, anything else inspected, nothing for undefined. An error prints its stack to
stderr and the exit code is 1. A signal ends it with 130.
On a server
Tinker works in every environment: whoever has a shell on the server can already do anything the app can. Where the app is
protected, in production, a staging server included, or without a NODE_ENV, the banner says so in red and names the database:
PRODUCTION — NODE_ENV=production, APP_ENV=staging, db pgsql (db.internal:5432/app): every change is real. It names the driver, host and
database, never a user or a password. With --execute the same line goes to stderr, so a script's stdout keeps only the value.
--sandbox takes back the default connection's writes; on Postgres the rows it wrote stay locked until the session ends, so keep it short.
History
The inputs of interactive sessions are kept in storage/framework/tinker_history, the last 1000 lines. A new file is readable
only by its owner, and an existing one is made owner-only too (if that fails, the session keeps no history). It is plain text: a password you hash or a token you paste is in it. --no-history keeps none. The history
holds inputs only, never what the REPL printed.
Lint
A new app has a lint preset, .oxlintrc.json, and pnpm lint runs oxlint with it. The
preset is yours to change. marmeon make:lint-config writes it, and --force writes it anew over your changes.
Its main rule: client code imports server code as types only. A view needs its controller's type, never the class:
import type { ShowNoteController } from '../controllers/ShowNoteController.ts'; // fine
import { ShowNoteController } from '../controllers/ShowNoteController.ts'; // a lint error in a viewA value import would bundle the controller, and everything it imports, into the browser. In views, layouts and the client
entry, the preset refuses value imports of server modules: the conventions that Server code in the browser
lists and the folders package.json declares under Server folders of your own. After you
change that declaration, run marmeon make:lint-config --force (with --boundaries, if you use it) to write the preset anew. marmeon check warns when the preset was written for other server modules and names the command.
The option serverModules of marmeon() is not in the preset. With --boundaries, a !glob does not take back a folder outside
modules/, such as config/ or domain/, and a ! on a file in modules/<name>/ holds only inside that module: from another
module the import is a boundary error anyway. Everywhere it asks for import type { X } instead of import { type X }, since the
inline form still loads the module.
The lint sees what an import says, not the file it resolves to. The marmeon() Vite plugin is the stricter check: it follows
every import of client code, also through a helper in between, and fails the build with the file and the line. The preset shows
the common case in the editor first.
In every file, tests included, the preset refuses imports of @marmeon/<package>/internal. Those subpaths are the framework's
own code and can change in any release; use the package's entry.
The preset also turns off the warning for unused private class members, in every class. That lets an event class carry
readonly #event = true, which make:event writes: the field is never read, and it makes the class a type of its own. The
events page explains why. A private member your own classes no longer use is not reported either.
--boundaries adds a second rule: a module imports another module only through its entry, #modules/<name>. The
modules page explains it. Without the flag, nothing about the structure of your modules is
checked.