mq-task
mq-task is a task runner that executes code blocks in Markdown files, selected by section title. Your tasks.md or README.md (or any Markdown file) is the task file: the documentation and the automation are the same text.
It is built on mq, a jq-like tool for Markdown, which parses the document and extracts sections.
## build
```bash
cargo build --release
```
## ci
```meta
depends = ["lint", "test", "build"]
parallel = true
```
```bash
echo "all checks passed"
```
mq-task ci
Features
- Run code blocks from any section, in any language with a configured runtime
- Task dependencies, with parallel fan-out / fan-in and calls with arguments
- Loops (
forover lists, globs, matrices and another task's output) anddefercleanup - Conditions (
if), retries, timeouts,ignore_error,promptconfirmation, and output passing between tasks - Shared variables, fixed or computed by a command (
vars) - Import tasks from other Markdown files
- Skip up-to-date tasks (
sources/outputs/status) and--watchmode - Dependency graph (text and Mermaid) and shell completions
- Finds
tasks.md(orREADME.md) from any subdirectory; completes task names; suggests fixes for typos inmetaand task names mq-task checkvalidates the task file (unknown keys, missing dependencies, cycles, missing runtimes)- Scripting and CI options:
--summary,list --json,--output group,--yes - Interactive TUI with search, argument prompts and live progress
Warning
mq-taskis under active development.
Head to Getting Started to install it and run your first task.
Getting Started
- Install
mq-task - Run your first task with the Quick Start
- Tune runtimes in Configuration
- Coming from
justor Task? Read how the concepts map
Install
Quick install
curl -sSL https://task.mqlang.org/install.sh | bash
The installer will:
- Download the latest
mq-taskbinary for your platform (Linux, macOS or Windows; x86_64 or aarch64) from GitHub Releases - Verify its SHA-256 checksum
- Install it to
~/.local/bin/ - Add
~/.local/binto yourPATHin your shell profile (bash, zsh or fish)
Restart your terminal or source your shell profile afterwards.
Windows
In PowerShell (5.1 or 7):
irm https://task.mqlang.org/install.ps1 | iex
It downloads mq-task-x86_64-pc-windows-msvc.exe (Arm64 Windows runs it emulated), verifies its SHA-256 checksum, installs it to %LOCALAPPDATA%\mq-task\bin and adds that folder to your user PATH. Open a new terminal afterwards.
A piped script cannot take parameters, so it reads environment variables:
| Variable | Meaning |
|---|---|
MQ_TASK_VERSION | Release tag to install, e.g. v0.2.4 (default: the latest) |
MQ_TASK_INSTALL_DIR | Where to put mq-task.exe |
MQ_TASK_NO_MODIFY_PATH | 1 leaves PATH alone |
$env:MQ_TASK_VERSION = "v0.2.4"; irm https://task.mqlang.org/install.ps1 | iex
The bash runtime needs Git Bash or WSL on PATH; see Configuration for choosing another runtime such as pwsh.
Cargo
cargo install --git https://github.com/harehare/mq-task.git
Verify
mq-task --version
Quick Start
A task is a heading followed by one or more code blocks. mq-task init writes a small tasks.md to start from; or create one yourself (the tasks can also live in your README.md):
## hello
```bash
echo "Hello from mq-task"
```
List the tasks and run one:
mq-task # list tasks in tasks.md (or README.md)
mq-task hello # run the "hello" task
mq-task -f docs/dev.md hello # use another file
mq-task hello is shorthand for mq-task run hello.
Passing arguments
Arguments after -- are exposed as MX_ARGS (space-joined) and MX_ARG_0, and so on
## greet
```bash
echo "Hello, $MX_ARG_0"
```
mq-task greet -- world
Dry run
--dry-run prints what would be executed without running anything.
Next
Which file is used
Without -f, mq-task looks for tasks.md and falls back to README.md. The search starts in the current directory and walks up to the repository root (the directory holding .git), so tasks work from any subdirectory. A tasks.md anywhere on the way up wins over a nearer README.md.
When the file is found in a parent directory, mq-task switches to that directory before running (like just), so relative paths in tasks refer to the project root. It prints using <path> in that case. With -f (or MQ_TASK_FILE) nothing is searched and the working directory is left alone.
Configuration
mq-task init --config creates an mq-task.toml with default runtime settings. It is picked up automatically when it sits next to the task file. Use -c/--config (or MQ_TASK_CONFIG) to point at another file. Unknown keys are an error.
default_task = "build"
[runtimes]
bash = "bash"
sh = "sh"
python = "python3"
ruby = "ruby"
node = "node"
javascript = "node"
js = "node"
php = "php"
perl = "perl"
[runtimes.go]
command = "go run"
execution_mode = "file"
[runtimes.jq]
command = "jq"
execution_mode = "arg"
Commands with spaces or quotes
A runtime command is split into words like a shell would, so a program path with spaces can be quoted:
[runtimes]
python = '"/opt/my tools/python3" -u'
On Windows a backslash is an ordinary character (it separates path components), and only double quotes group words:
[runtimes]
python = '"C:\Program Files\Python312\python.exe" -u'
On Unix the usual rules apply: single quotes are literal and a backslash escapes the next character. An unterminated quote is a configuration error.
Execution modes
| Mode | Behaviour |
|---|---|
file (default) | Write the code to a temp file and pass it as an argument. stdin stays interactive. |
stdin | Pipe the code into the command's stdin. The script itself cannot read the terminal. Use for psql, redis-cli and similar clients |
arg | Pass the code as a command-line argument (e.g. jq, mq). |
default_task
Top-level key (outside [runtimes]). The task run when mq-task is invoked without a task name.
In the task file
runtimes and default_task can also be written in the document-wide meta block (before the first heading), so that a single Markdown file carries everything it needs and no mq-task.toml has to sit next to it:
```meta
default_task = "build"
runtimes = { python = "python3.12", go = { command = "go run", execution_mode = "file" } }
```
runtimes takes the same values as [runtimes] above. The file adds to the built-in runtimes and replaces those it names. Precedence, highest first:
-r/--runtimeon the command line- the languages set in
mq-task.toml(and itsdefault_task) - the task file's own
metablock - the built-in defaults
So a machine can still pin its own interpreter with mq-task.toml, and a file in the task file is only a default for everyone else. Imported files can add runtimes for languages the importing file leaves alone. mq-task check knows about them, and reports a default_task that names no task.
Overriding from the CLI
mq-task build -r python:python3.11 -e file
mq-task build --lang bash # only run bash blocks
Coming from just or Task
mq-task covers what most justfiles and Taskfile.ymls do, but it is not a drop-in replacement: the task file is a Markdown document, and a few things work differently. This page maps the concepts and says plainly what is missing. There is no automatic converter; moving a file by hand takes a few minutes.
How mq-task thinks
- A heading is a task and the code blocks under it are what runs. The prose is the description (
mq-task list,--summary, shell completion). - A block is one script, not one command per line. In
justevery line runs in its own shell; here abashblock runs top to bottom in a single shell, socdand variables carry over. Addset -eyourself if you want to stop at the first failure. - The block's language picks the interpreter (
bash,python,node, ...), so whatjustcalls a shebang recipe is simply a ```python block. - Values reach scripts as environment variables, whatever the language. There is no
{{ }}text substitution into the script (see Variables). - mq-task does not echo commands.
-vprints each block before it runs. - Without
-f, the task file is searched for upwards from where you are (tasks.mdfirst), and mq-task changes to its directory before running, likejust. With-f, tasks run where you are.
From just
| just | mq-task |
|---|---|
build: with indented lines | ## build with a ```bash block |
test: build | ```meta with depends = ["build"] |
deploy env="staging": and {{env}} | params = ["env=staging"] and $MX_PARAM_ENV |
*args / +args | the rest of the command line: $MX_ARGS, $MX_ARG_0, ... |
version := "1.0" | vars = { version = "1.0" } (referenced as $version or ${version}) |
v := `git describe` | vars = { v = { sh = "git describe" } } |
set dotenv-load | dotenv = [".env"] |
set shell := ["zsh", "-c"] | runtimes in mq-task.toml or in the task file's meta block, e.g. runtimes = { bash = "zsh" } |
shebang recipe #!/usr/bin/env python3 | a ```python block |
[private] or a leading _ | a leading _ or private = true |
[confirm("Sure?")] | prompt = "Sure?" (--yes skips it) |
[linux], [macos], [windows], [unix] | if = 'os() == "linux"' |
env_var("HOME"), os() | ${HOME} in vars; getenv("HOME") and os() in an if condition |
alias b := build | alias = ["b"] |
import "x.just" / mod x | imports = ["x.md"], used as x:task |
@recipe / set quiet | the default: nothing is echoed |
just --list, --summary | mq-task, mq-task <task> --summary, mq-task list --json |
just --choose | mq-task tui |
just --dry-run | mq-task <task> --dry-run |
just a b | mq-task a b (arguments after -- go to a single task only) |
just --no-deps | mq-task <task> --no-deps |
just --quiet | mq-task <task> -q |
| first recipe is the default | default_task = "build" in mq-task.toml or the task file's meta block |
just --fmt, --evaluate | no equivalent (mq-task check validates the file) |
Not available: recipe groups ([group]), {{ }} interpolation of arguments or functions into the script text, invocation_directory() (a task always runs in the file's directory unless you set dir), and running a single line of a recipe.
From Task
| Task | mq-task |
|---|---|
tasks: map, desc/summary | headings, with the prose as the description |
cmds | the lines of a code block |
deps | depends. Task runs deps in parallel by default; mq-task runs them in order unless the task sets parallel = true |
task: other with vars inside deps | depends = ["other name=value"] |
vars, sh: | vars = { A = "x", B = { sh = "cmd" } } |
{{.VAR}} templates | $VAR / ${VAR}; ${VAR} inside vars values is expanded by mq-task |
env, dotenv, dir | env, dotenv, dir |
sources / generates | sources / outputs (content checksums, like Task's default) |
status | status (commands that exit 0 when the task is up to date) |
preconditions | requires for variables, if to skip, or a check in the script |
for over a list, a matrix, sources | for = [..], { matrix = .. }, { glob = .. }; over a variable: { from = "task" } |
defer | defer = ["cleanup"] |
ignore_error | ignore_error = true |
prompt | prompt = "..." |
run: once | once = true |
platforms | if = 'os() == "linux"' |
silent | the default (use -v to see the code) |
internal | a leading _ or private = true |
aliases | alias |
includes | imports, namespaced as file:task |
includes with taskfile, flatten, optional | imports = [{ path = "x.md", as = "ns", flatten = true, optional = true }] |
requires: vars | requires |
requires: vars with enum | params table with choices |
--watch, interval | --watch, --interval |
--parallel, --concurrency | --parallel, -j |
--force | --no-cache |
--list, --summary | mq-task, --summary |
--dry, --yes | --dry-run, --yes |
--status | --status (exit 1 when a task would run) |
--silent | -q/--quiet |
task a b | mq-task a b |
sources with exclude: | sources = ["src/**", "!src/gen/**"] |
--output group with group.begin/end | --output group (on GitHub Actions it emits ::group:: automatically) |
Not available: Go-template functions and conditionals, per-include vars, method: timestamp, label, calling another task from the middle of a script (use depends, defer, or run mq-task other from the script), and set/shopt options.
A small example
A justfile:
default: test
build profile="debug":
cargo build --profile {{profile}}
test: build
cargo test
deploy env="staging": test
@echo "deploying to {{env}}"
The same tasks in tasks.md:
## build
```meta
params = ["profile=debug"]
```
```bash
cargo build --profile "$MX_PARAM_PROFILE"
```
## test
```meta
depends = ["build"]
```
```bash
cargo test
```
## deploy
```meta
depends = ["test"]
params = ["env=staging"]
```
```bash
echo "deploying to $MX_PARAM_ENV"
```
and default_task = "test" in mq-task.toml. A Taskfile.yml converts the same way: each key under tasks: becomes a heading, cmds becomes the code block and deps, vars and the other keys move into the meta block as in the table above.
Checking the result
mq-task check # finds typos, missing dependencies, cycles, missing runtimes
mq-task # lists the tasks
mq-task <task> --dry-run
Guide
Each page covers one feature, from the basics to scheduling, caching and tooling. Task behaviour is configured with a meta code block (TOML) inside the task's section. See the Meta keys reference for the full list.
Writing Tasks
Every heading is a task. The task name is the heading text; the commands are the code blocks beneath it. By default ## headings are tasks.
## build
Compile the project.
```bash
cargo build
```
- Several code blocks in one section run in order.
- The prose under the heading is the task description (shown in
listand the TUI).mq-task <task> --summaryprints it together with the task's dependencies, parameters and options, without running anything. - The language of the fence selects the runtime from configuration.
- A
metablock configures the task; it is not executed.
Code blocks that are not commands
When the task file is a README.md, sections often hold examples next to the commands. Blocks that are not commands are skipped:
- A block whose info string contains
no-runis never run:```bash no-run. - A block in a data or output language (
text,console,output,log,json,yaml,toml,xml,html,css,csv,diff,ini,markdown,mermaid,dockerfile, ...) is skipped, unless the language has a runtime under[runtimes](then it runs, e.g. ajsonblock for ajqruntime). Other languages without a runtime are still an error, so a typo such aspyhtonis caught. - A block without a language runs in the default shell:
sh, orpowershellon Windows. Setdefault_languageinmq-task.tomlto change it (e.g.default_language = "bash"); mark output-only fences withtextto keep them from running.
A section whose blocks are all skipped is not a task: it is not listed and check ignores it.
Document-wide meta
A meta block before the first heading applies to every task:
```meta
env = ["REGION=staging"]
dir = "services/api"
```
Precedence, lowest to highest: document-wide meta → the task's own meta → CLI flags.
Seeing what runs
-v/--verbose prints every code block just before it runs, on stderr so that captured output and pipes are not affected:
$ mq-task build -v
▶ build
▸ bash
cargo build --release
The block is shown for each loop item and each deferred task, and with the working directory when the task has one (▸ bash in services/api). With --output group it is part of the task's block. --dry-run already shows the code and its context, so -v adds nothing there.
Typos
A task name that does not exist is reported with the closest match, and so is a mistyped entry in depends:
$ mq-task deploi
Error: Section not found: deploi (did you mean `deploy`?)
Dependencies
## format
```bash
cargo fmt
```
## lint
```meta
depends = ["format"]
```
```bash
cargo clippy
```
## test
```meta
depends = ["lint"]
```
```bash
cargo test
```
mq-task test runs format → lint → test.
- Multiple dependencies:
depends = ["format", "lint"] - Several tasks from the command line:
mq-task lint testrunslintthentestas one run, so a dependency they share runs once --no-depsruns only the tasks you name and skips theirdepends:mq-task test --no-deps- A shared dependency runs only once
- Circular dependencies are reported as an error
Calling a dependency with arguments
A dependency can be followed by arguments, bound exactly like command-line arguments: name=value for named parameters, the rest positionally.
## deploy
```meta
params = ["env", "region=us"]
```
```bash
echo "deploying to $MX_PARAM_ENV ($MX_PARAM_REGION)"
```
## release
```meta
depends = ["deploy staging", "deploy env=prod 'region=eu west'"]
```
- Words are split on whitespace; use single or double quotes for values containing spaces. A task title containing spaces still works as a plain dependency (
depends = ["Build App"]). - The same task called with different arguments runs once per distinct argument list; identical calls are shared.
- Calls appear as
deploy[env=prod ...]in progress output and asdeploy (env=prod ...)ingraph. once = trueon the called task makes every call share a single run, whatever the arguments; the first call wins.- Arguments apply to that call only; the arguments given on the command line still belong to the requested task.
Parallel Execution
By default dependencies run one after another in declaration order. Set parallel = true to run them concurrently; the task starts after all of them finish (fan-out / fan-in).
## ci
```meta
depends = ["lint", "test", "build"]
parallel = true
```
```bash
echo "all checks passed"
```
- Only real dependency edges constrain ordering: a task starts as soon as its own dependencies are done.
- Output is prefixed with the task name (for example
lint │ output; see Output modes); each task reports✔/✘with its duration. - The first failure aborts the run: running tasks (and the processes they started) are stopped.
-k/--keep-goinglets independent tasks finish; dependents of a failed task are not run. --parallelforces concurrency regardless of the file;-j N/--jobs Ncaps concurrent tasks (-j 1is sequential). Default: number of CPUs.- stdin is closed for tasks in parallel runs; keep interactive tasks sequential. Dry-run is always sequential.
Output modes
--output chooses how task output is shown:
| Mode | Behavior |
|---|---|
| (default) | raw output for sequential runs, prefixed lines (lint │ ...) for concurrent ones |
interleaved | raw lines as they arrive, never prefixed |
prefixed | every line tagged with its task name, even when sequential |
group | each task's output is held back and printed as one block when the task finishes, which keeps CI logs readable (each task holds at most 64 MiB; past that the held part is printed and the rest streams with a task │ prefix) |
mq-task ci --output group
On GitHub Actions (GITHUB_ACTIONS=true) group wraps each task's block in ::group::name / ::endgroup::, so the log folds per task. A failed run also prints an ::error:: annotation with the error, in any output mode.
prefixed and group pipe task output, so stdin is closed for tasks (as in parallel runs) and programs may stop colouring their output. The TUI draws its own log pane and ignores --output.
Loops
for runs a task once per item. The task body is repeated for every item, and each iteration sees the item as environment variables.
## convert
```meta
for = ["a.png", "b.png", "c.png"]
```
```bash
convert "$MX_ITEM" "${MX_ITEM%.png}.webp"
```
Sources of items
| Form | Items |
|---|---|
for = ["a", "b", 3] | the listed values (strings, numbers and booleans) |
for = { glob = "assets/*.png" } | files and directories matching the glob(s), sorted, relative to the task's directory |
for = { matrix = { os = ["linux", "macos"], arch = ["x64", "arm64"] } } | every combination of the axes |
| for = { from = "list-files" } | the lines of another task's captured output (see below) |
glob also accepts an array of patterns. Matrix axes are iterated in alphabetical order of their names, the last axis varying fastest.
Variables
| Variable | Value |
|---|---|
MX_ITEM | the current item (list and glob) |
MX_INDEX | the zero-based position of the iteration |
MX_<AXIS> | the value of each matrix axis, e.g. MX_OS, MX_ARCH |
MX_<AS> | the item under the name given by as (list and glob) |
## greet
```meta
for = ["alice", "bob"]
as = "name"
```
```bash
echo "hello $MX_NAME" # same value as $MX_ITEM
```
Execution
- Iterations of lists, globs and matrices run one after another by default. With
parallel = true(or--parallel/-j N) they run concurrently, subject to-j. - Each iteration is a separate run of the task:
if,retries,timeout,sources/outputsanddeferapply per iteration. The up-to-date check is recorded per item. - The first failing iteration aborts the run. With
--keep-goingthe remaining iterations still run. - Tasks that depend on a looped task start after all its iterations finished, and a failed iteration fails the dependency.
- With
capture = true, dependents see the outputs of all iterations joined by newlines inMX_OUTPUT_<TASK>. - A loop without items (an empty list, a glob without matches) is reported as skipped rather than as an error.
- Iterations show up as
task[item]in progress output, the TUI andgraph.
Looping over another task's output
from runs the task once per line of a dependency's output, for work lists that are only known at run time. The source must be a dependency (direct or indirect) that sets capture = true:
## list-files
```meta
capture = true
```
```bash
git ls-files '*.md'
```
## lint-each
```meta
depends = ["list-files"]
for = { from = "list-files" }
as = "file"
```
```bash
markdownlint "$MX_FILE"
```
- Blank lines are ignored; each remaining line is one item (
MX_ITEM,MX_INDEXand theasname work as usual). - The items run one after another inside the task, so
parallelhas no effect on them. The first failing item stops the loop; each item gets its ownretriesandtimeout. deferruns once after the last item, andsources/outputscaching covers the task as a whole (a changed source output re-runs it).- If the source printed nothing, the task is skipped like any empty loop. This includes a source that was itself skipped (by
if,statusor an up-to-date check), because a skipped task captures no output. - Progress shows a single node for the task, with a
↳ task[item]line before each item.
Combining with call arguments
A loop pairs well with dependency arguments:
## build
```meta
params = ["profile=dev"]
for = { matrix = { target = ["x86_64", "aarch64"] } }
```
```bash
cargo build --profile "$MX_PARAM_PROFILE" --target "$MX_TARGET-unknown-linux-gnu"
```
## release
```meta
depends = ["build profile=release"]
```
Cleanup with defer
defer lists tasks that run after a task's body finishes, whether it succeeded or failed. Use it for cleanup that must not be skipped.
## cleanup
```bash
docker compose down
```
## integration
```meta
defer = ["cleanup"]
```
```bash
docker compose up -d
./run-integration-tests.sh
```
- Deferred tasks run in the order they are listed, and each may be called with arguments:
defer = ["notify status=done"]. - They run only if the task actually started: a task skipped by
ifor because it is up to date does not run itsdefer. - They also run when the body failed, timed out, or the run was aborted by another failing task, by Ctrl+C or by
SIGTERM/SIGHUP(signals). Deferred tasks are shielded from that interruption, so cleanup can finish; press Ctrl+C again to cut it short. - With
retries, deferred tasks run once, after the last attempt. - The task's result is the body's result. If the body succeeded but a deferred task fails, the task fails with the deferred task's exit code. If the body failed, its error is kept and a failing deferred task is only reported.
- Deferred tasks see the same loop variables and dependency outputs as the task, and in a loop they run after every iteration.
- A deferred task must not have
dependsof its own.
Conditions
if skips a task when its condition is false. A skipped task does not block its dependents.
## deploy
```meta
if = 'flag("CI") && os() == "linux"'
```
```bash
./deploy.sh
```
| Expression | True when |
|---|---|
flag("NAME") | the variable is set and not empty, 0 or false |
getenv("NAME") == "x", getenv("NAME") != "x" | the variable equals / differs from x |
os() == "linux" | the OS is linux, macos or windows |
exists("path") | the path exists (relative to the task's working directory) |
which("cmd") | cmd is on PATH |
!expr, a && b, a || b | boolean combinations; parentheses group |
Variables are looked up in --env, the task's meta/params, then the process environment.
A condition is an mq expression that must evaluate to true or false, so anything else mq offers (string functions, contains and so on) works too. Use getenv/flag rather than mq's built-in env(), which only sees the process environment.
Confirmation Prompts
prompt asks for confirmation before a task runs. It is meant for tasks with side effects that are hard to undo.
## deploy
```meta
prompt = "Deploy to production?"
```
```bash
./deploy.sh
```
$ mq-task deploy
? Deploy to production? [y/N] y
yoryes(any case) confirms; anything else, including end of input, declines and fails the task with exit code1.--yes/-yanswers yes to every prompt, for scripts and CI.echo y | mq-task deployworks too.- The question is asked after the task's
ifand up-to-date checks, so a skipped task never prompts. - A looped task is confirmed once, not once per item.
--dry-runprints the prompt instead of asking.- Prompts need the terminal, so they cannot be asked in parallel runs, with
--output prefixedorgroup, or inside the TUI: those fail with a message asking for--yes. In the TUI, pressxto run the task in the terminal instead.
Retries and Timeouts
## flaky-integration
```meta
retries = 3 # up to 4 attempts in total
retry_delay = "2s" # default: 1s
timeout = "5m" # per attempt; exit code 124 when exceeded
```
```bash
./run-integration-tests.sh
```
- Durations accept
ms,s,m,h; a bare number is seconds. - Only runtime failures are retried. Missing runtimes or parameters fail immediately.
- A task with
timeoutruns in its own process group so the whole tree is stopped. It therefore cannot read from the terminal.
Ignoring failures
ignore_error = true lets a task fail without failing the run:
## lint-docs
```meta
ignore_error = true
```
```bash
markdownlint docs/
```
- The failure is reported on stderr, but the task counts as successful: dependents still run and the exit code stays
0. - It applies after
retriesare exhausted, and also to atimeout. - Only runtime failures are ignored. Missing runtimes, missing parameters and cancellation still stop the run.
- An ignored failure is never recorded as "up to date" for
sources/outputs, so the task runs again next time. defertasks still run.
Passing Output Between Tasks
capture = true exposes a task's stdout (trailing newline removed) to dependents as MX_OUTPUT_<TASK> (the title upper-cased with other characters replaced by _). The output is still printed.
## version
```meta
capture = true
```
```bash
git describe --tags
```
## release
```meta
depends = ["version"]
```
```bash
echo "releasing $MX_OUTPUT_VERSION"
```
Captured output reaches direct and transitive dependents. Because stdout is piped, programs may stop colouring it.
Importing Tasks
List files in the document-wide meta block. Their tasks become available as <file name>:<task>.
```meta
imports = ["ci/checks.md", "deploy.md"]
```
## release
```meta
depends = ["checks:lint", "deploy:staging"]
```
Options
An entry can be a table instead of a path:
```meta
imports = [
"ci/checks.md",
{ path = "deploy.md", as = "ship" },
{ path = "local.md", optional = true },
{ path = "common.md", flatten = true },
"tasks/*.md",
]
```
| Key | Meaning |
|---|---|
path | The file, or a glob such as tasks/*.md (matches are imported in sorted order, each named after its file; a glob without matches imports nothing, and the importing file is never matched) |
as | The namespace to use instead of the file name: ship:staging for deploy.md. Not with a glob or flatten |
optional | A missing file is ignored instead of being an error. A file that exists but is broken is still an error |
flatten | Add the tasks under their own names, without <name>:. When a name is already taken by a task of the importing file, check reports the clash and the importing file's task wins |
Paths and the other rules:
- Paths are relative to the importing file; imports nest (
a:b:task); cycles are rejected. - Inside an imported file,
dependsuse that file's own short names. - The imported file's document-wide
env/dirapply to its tasks. Relativedirresolves against wheremq-taskwas invoked.
Caching and Watch Mode
Declare the files a task reads with sources (globs). The task is skipped when sources, code, arguments and environment are unchanged since its last successful run. With outputs, it also runs if an output is missing.
## build
```meta
sources = ["src/**/*.rs", "Cargo.toml"]
outputs = ["target/release/app"]
```
```bash
cargo build --release
```
Fingerprints live in .mq-task/cache.json in the invocation directory. Consider git-ignoring .mq-task/. --no-cache ignores them.
Excluding files
A pattern starting with ! removes the files it matches from sources, wherever it stands in the list:
sources = ["src/**/*.rs", "!src/generated/**"]
Like any pattern it is relative to the task's directory, and a single * does not cross directories (!*.rs excludes only top-level files). Exclusions also apply to --watch.
Checking without running
--status reports whether each task would run, without running it, and exits with 1 when any would. Use it in scripts and hooks:
$ mq-task build --status
✘ build out of date (sources changed, outputs are missing or it has not run yet)
$ mq-task build && mq-task build --status
✔ build (up to date)
A task is up to date when its status commands pass or its sources and outputs are unchanged (or its if is false). A task with neither always runs. Tasks that depend on one that is out of date are reported as not checked. -q prints only the out-of-date ones.
Custom up-to-date checks with status
When "unchanged inputs" is not the right question, status lists shell commands that decide it. If all of them exit 0 the task is up to date and skipped:
## install
```meta
status = ["test -d node_modules", "test node_modules -nt package-lock.json"]
```
```bash
npm ci
```
- Commands run with
sh -c(cmd /Con Windows) in the task's working directory and environment, with output discarded. statusis checked beforesources/outputs; if it does not pass, the normal fingerprint check still applies.--no-cacheignoresstatustoo, and--dry-runnever runs it.
Watch
mq-task test --watch
mq-task test --watch --interval 1s # check for changes every second (default 300ms)
Re-runs whenever any sources or dotenv file of the task or its dependencies, or the task file, change.
Parameters, Env and Working Directory
Named parameters
A bare name is required; name=value sets a default.
## deploy
```meta
params = ["env=staging", "region"]
```
```bash
echo "deploying to $MX_PARAM_ENV / $MX_PARAM_REGION"
```
mq-task deploy -- region=eu # env falls back to "staging"
mq-task deploy -- prod eu # positional, in declaration order
mq-task deploy -- env=prod region=eu # named
Parameters are exposed as MX_PARAM_<NAME>. A required parameter without a value is an error.
Choices and descriptions
An entry of params can also be a table, to restrict the values and explain the parameter:
## deploy
```meta
params = [
{ name = "env", default = "staging", choices = ["staging", "prod"], desc = "target environment" },
"tag=latest",
]
```
| Key | Meaning |
|---|---|
name | The parameter name (required) |
default | The value used when none is given; without it the parameter is required |
choices | The accepted values; anything else is an error that names the choices and suggests the closest one |
desc | A line of help shown by --summary, the TUI and list --json (description) |
Tables and the short "name=default" strings can be mixed in one list |
$ mq-task deploy --summary
params env=staging [staging|prod] - target environment; tag=latest
$ mq-task deploy -- prd
Error: Invalid value 'prd' for parameter 'env' of task 'deploy' (one of: staging, prod; did you mean `prod`?)
The default must be one of the choices, and an empty choices list is rejected when the file is loaded. Values given through depends = ["deploy env=prod"] are checked too.
A word of the form name=value is a named argument, so a name the task does not declare is an error (with a suggestion for a near miss) instead of becoming a value:
$ mq-task deploy -- regoin=eu
Error: Unknown parameter 'regoin' for task 'deploy' (did you mean `region`?)
This applies to tasks that declare params; a task without them takes any arguments. A value that merely contains = (https://x.test/?a=1) is still a plain value, because it is not of the form name=value.
Environment and directory
mq-task deploy --env REGION=eu --env DEBUG=1
mq-task deploy --dir ../other-project
Defaults can be declared in meta:
## deploy
```meta
env = ["REGION=staging", "LOG_LEVEL=info"]
dir = "services/api"
```
CLI --env / --dir override the meta defaults for that run.
Required variables
requires fails a task early, before anything runs, when variables it needs are missing or empty:
## deploy
```meta
requires = ["API_TOKEN", "REGION"]
```
```bash
./deploy.sh
```
Error: Task 'deploy' requires API_TOKEN, REGION to be set
Variables are looked up in --env, the task's meta, params and dotenv files, and the process environment. All missing names are reported at once. Tasks skipped by if are not checked, and --dry-run does not check at all.
.env files
dotenv loads variables from .env-style files. It works per task and, in a meta block before the first heading, for every task:
```meta
dotenv = [".env"]
```
## deploy
```meta
dotenv = [".env.production"]
```
```bash
echo "deploying with $API_URL"
```
- Paths are relative to the task's working directory (
dir). A file that does not exist is ignored, so optional files such as.env.localare safe to list. - Files are read in the order listed and later files win.
- Precedence, lowest first:
dotenvfiles → document-wideenv→ the task'senv→ params →--env. A variable that is already set in the process environment is not overridden by a file, soAPI_URL=... mq-task deploystill wins over.env. - With
--watch, changes to the listed.envfiles re-run the task. - Supported syntax:
KEY=value,export KEY=value,#comments, single quotes (literal) and double quotes (with\n,\t,\",\\escapes). There is no$VARexpansion. A malformed line is an error that names the file and line.
Variables
vars gives names to values, so several tasks can share them. A value is either fixed or the output of a shell command.
```meta
vars = { NAME = "app", VERSION = { sh = "git describe --tags" }, IMAGE = "${NAME}:${VERSION}" }
```
## build
```bash
docker build -t "$IMAGE" .
```
A meta block before the first heading defines variables for every task; a task's own meta adds to them or replaces them. Each variable reaches the task as an environment variable, whatever language the code block uses.
Values
| Form | Value |
|---|---|
NAME = "app" | the string; numbers and booleans are turned into strings |
VERSION = { sh = "git describe" } | the output of the command, without trailing newlines |
| VERSION = { mq = "...", from = "CHANGELOG.md" } | the result of an mq query over a file, one result per line |
Commands run with sh -c (cmd /C on Windows) in the task's working directory. If one fails, the task does not run and the error shows the command, its exit code and the first line of its error output.
Values from Markdown, HTML or text files
{ mq = "query", from = "file" } runs an mq query over a file and uses the result, so a variable can come from a document that already holds the information, without a grep or sed:
```meta
vars = { VERSION = { mq = "nodes | filter(is_h2) | first() | to_text()", from = "CHANGELOG.md" }, TAG = "v${VERSION}" }
```
## release
```bash
git tag "$TAG"
```
- The query is evaluated the way the
mqcommand does it, so the same text works withmq '<query>' CHANGELOG.md. A selector such as.h2runs on every node and yields the headings. To pick one result over the whole document, start fromnodes:nodes | filter(is_h2) | first(). - Results are printed one per line, and nodes a selector does not match are left out. A heading is turned into text with
to_text(); without it you get the Markdown of the node. - The kind of input follows the extension of
from:.html/.htmas HTML,.mdxas MDX,.txtas plain text, anything else as Markdown.fromis relative to the task's working directory. ${NAME}infromrefers to other variables, and so does the query (a name that is not a variable stays as it is, since mq has its own${...}in interpolated strings).- Like
sh, the query runs once per run, before the task starts, and--dry-runshows<mq: file query>instead. A missing file or a query that fails is an error that names the variable.
Referring to other variables
${NAME} inside a value, or inside an sh command, is replaced by that variable:
vars = { REGISTRY = "ghcr.io/me", IMAGE = "${REGISTRY}/app:${VERSION}", VERSION = { sh = "git describe" } }
- Order does not matter; mq-task evaluates what a variable needs first. A loop (
AneedsBneedsA) is an error that names the path. ${NAME}can also name a.envvalue, anenventry, a parameter (${MX_PARAM_PROFILE}), a loop variable (${MX_ITEM}), a dependency's output (${MX_OUTPUT_VERSION}) or any variable of the process environment.- With
for = { from = "task" }the item is known only when the task runs, so a variable that uses${MX_ITEM}(directly or through another variable) is evaluated once per item. Variables that do not use it are evaluated once. - A variable that mentions its own name extends the outer value:
PATH = "${PATH}:/opt/tools". - In a plain value an unknown name is an error. Inside an
shcommand it is left alone, so the shell can use its own${i}or${x:-default}. $${NAME}writes a literal${NAME}. Only the braced form is expanded:$NAMEand$(...)are left to the shell.- Variables that were evaluated earlier are also exported to later
shcommands. Mention a variable as${NAME}when you depend on it, so the order is guaranteed.
Precedence
From lowest to highest: .env files, vars, env, parameters, --env. A variable of the same name as an env entry or a --env value is not evaluated at all, and the variables that refer to it see that value:
mq-task release --env VERSION=2.0.0 # the `git describe` command is skipped
When commands run
- A command runs once per run for the same text, directory and environment, however many tasks use it, and again on the next run (
--watchevaluates it afresh each time). Tasks whose environment differs (for exampleREGIONset byenv) each get their own result. - Commands run before the task starts, so they run even when the task is then skipped (
ifis false, it is up to date) or itspromptis declined. They need the variables to decide that, so keep them free of side effects. - A command is stopped by the task's
timeoutand when the run is cancelled, like the task itself. - Variables are part of what decides whether a task is up to date: if a computed value changes, a task with
sourcesruns again. if,requiresandstatussee the variables.--dry-rundoes not run commands; it shows<sh: command>instead.
Imports
The variables of a document-wide meta block in an imported file apply to that file's tasks, as env does.
Aliases, Default and Private Tasks
Aliases
## build
```meta
alias = ["b"]
```
mq-task b runs build.
Default task
# mq-task.toml
default_task = "build"
mq-task with no task name runs build.
Private tasks
A title starting with _, or private = true in meta, hides the task from list/tui (list --all shows it). It can still be run and used as a dependency.
## _cleanup
```bash
rm -rf tmp/
```
Interactive TUI
mq-task tui
A searchable task list with a details pane (description, dependencies, params, options, code).
| Key | Action |
|---|---|
↑/↓, j/k | move |
/ | search titles, aliases, descriptions |
Enter | run inside the TUI (prompts when a param is required) |
a | run with arguments (name=value, positional; quote values containing spaces) |
x | leave the TUI and run in the terminal (interactive stdin works) |
q/Esc | quit |
While running, the top pane draws the dependency graph as a left-to-right workflow: one stage per column, each task with its state (○ pending, spinner running, ✔, ✘, ⊘ skipped, ↻ retry) and elapsed time. The bottom pane shows the log. Arrow keys (or hjkl) move the selection, v toggles the graph and a flat task list, Tab toggles combined / selected-task log, PgUp/PgDn scroll, q/Ctrl+C aborts, r re-runs. --parallel, -j, -k, --no-cache and --yes apply too.
Dependency Graph
mq-task graph ci # tree for one task
mq-task graph --format mermaid # Mermaid diagram of all public tasks
ci [parallel]
├── lint
└── test
└── build
The Mermaid output can be pasted into GitHub Markdown or any Mermaid renderer.
Checking a Task File
mq-task check looks for mistakes in the task file without running anything, and reports all of them at once. Use it in CI or in a pre-commit hook.
$ mq-task check
error: task 'build': `meta` block: unknown key `retires` on line 1 (did you mean `retries`?)
error: task 'deploy': depends on unknown task 'buil' (did you mean `build`?)
error: task 'test': circular dependency: test -> lint -> test
error: task 'lint': no runtime is configured for language 'cobol' (used by 'lint'); add it under [runtimes] in mq-task.toml
warning: task 'run': the name 'run' is also a command; run the task with `mq-task run run`
tasks.md: 4 errors, 1 warning
The command exits with 1 when there are errors, and with 0 otherwise. --strict makes warnings fail too.
What is checked
| Problem | Severity |
|---|---|
Unknown meta keys and invalid values (durations, vars, for, ...), in the file and in its imports | error |
depends, defer or for = { from } naming a task that does not exist, with a suggestion | error |
Dependency cycles, reported once as a -> b -> a | error |
for = { from } pointing at a task that is not a dependency or does not set capture = true; a deferred task that has dependencies | error |
| A language without a configured runtime | error |
A runtime that is configured but not found in PATH | warning |
Invalid glob patterns in sources, outputs and for = { glob } | error |
An if condition that does not parse | error |
| A task defined twice, an alias that clashes with another name, a parameter declared twice | error |
A task or alias named like a command (run, list, ...) | warning |
An imports file that is missing or imported twice under the same name | error |
A script that reads MX_PARAM_<NAME> for a parameter the task does not declare | warning |
A script that reads MX_OUTPUT_<TASK> when no dependency (direct or indirect) of the task captures it, with the reason: the task does not set capture = true, is not a dependency, or does not exist | warning |
A sources pattern that matches no files | warning |
The last three are mistakes that do not fail a run: the variable is just empty, and a task whose sources match nothing is skipped as up to date forever. Patterns are looked up from the current directory (or the task's dir), as a run does. A ! pattern is an exclusion and is not looked up.
Headings that contain nothing to run (such as a document title) are not tasks and are not checked.
Options
| Option | Meaning |
|---|---|
-f, --file <FILE> | the file to check (default: the nearest tasks.md, else README.md) |
-c, --config <CONFIG> | the configuration whose [runtimes] are used |
--strict | exit with 1 on warnings too |
--json | print { "file", "tasks", "diagnostics": [{ "severity", "task", "message" }] } |
In CI
- run: mq-task check --strict
Shell Completions
mq-task completes subcommands, options and the task names of your task file:
mq-task completions zsh > ~/.zfunc/_mq-task
mq-task completions bash > /etc/bash_completion.d/mq-task
mq-task completions fish > ~/.config/fish/completions/mq-task.fish
Supported shells: bash, zsh, fish, elvish, powershell.
The installed script asks mq-task for candidates every time you press Tab, so new tasks show up immediately:
$ mq-task de<TAB>
deploy (Ship it to production.)
- Task names and aliases are offered, with the first line of the description where the shell can show it. Private tasks (
_name) are hidden. - The file is found like for a run:
MQ_TASK_FILE, elsetasks.md/README.mdsearched upwards from the current directory. A-ftyped earlier on the same command line is not taken into account. - If there is no task file, or it cannot be parsed, nothing is offered and no error is shown.
Cookbook
Complete, copy-pasteable task files.
A CI pipeline in one file
## format
```bash
cargo fmt --check
```
## lint
```meta
sources = ["src/**/*.rs"]
```
```bash
cargo clippy -- -D warnings
```
## test
```meta
sources = ["src/**/*.rs", "tests/**/*.rs"]
retries = 1
```
```bash
cargo test
```
## ci
```meta
depends = ["format", "lint", "test"]
parallel = true
```
```bash
echo ok
```
Run it with mq-task ci -k to see every failure at once, or mq-task ci -j 2 to limit concurrency.
Release with captured version
## version
```meta
capture = true
```
```bash
git describe --tags --abbrev=0
```
## build
```meta
sources = ["src/**/*.rs"]
outputs = ["target/release/app"]
```
```bash
cargo build --release
```
## release
```meta
depends = ["version", "build"]
if = 'flag("GITHUB_ACTIONS")'
```
```bash
gh release upload "$MX_OUTPUT_VERSION" target/release/app
```
Multi-language tasks
Each fenced block uses the runtime for its language.
## report
```python
import json, sys
print(json.dumps({"ok": True}))
```
```bash
echo "done"
```
Add or change runtimes in mq-task.toml, or override one per run with -r python:python3.12.
Reference
Meta keys
A fenced block with the language meta (TOML) in a task section. Unknown keys and invalid values are an error, so a typo such as retires is caught instead of silently ignored:
Error: Invalid task file: task 'flaky': `meta` block: unknown key `retires` on line 1 (did you mean `retries`?)
imports and the other document-wide keys go in a meta block before the first heading. That block also accepts runtimes and default_task (Configuration).
| Key | Type | Description |
|---|---|---|
depends | array of strings | Tasks to run first; each may carry arguments ("deploy env=prod") |
once | bool | Run at most once per run, even when called with different arguments |
parallel | bool | Run depends and the items of list, glob and matrix loops concurrently |
for | array, { glob }, { matrix } or { from } | Run the task once per item (Loops) |
as | string | Extra variable name for the loop item (as = "file" sets MX_FILE) |
defer | array of strings | Tasks run after this one, even on failure (defer) |
if | string | Condition; task skipped when false |
retries | integer | Extra attempts after a failure |
retry_delay | duration | Wait between attempts (default 1s) |
timeout | duration | Per-attempt limit; exit 124 |
prompt | string | Ask for confirmation before running (Prompts) |
ignore_error | bool | Treat a failed run as success (Retries and Timeouts) |
capture | bool | Expose stdout as MX_OUTPUT_<TASK> to dependents |
sources | array of globs | Input files for up-to-date checks and --watch; a !pattern excludes files (details) |
status | array of strings | Shell commands; task skipped when all exit 0 (guide) |
outputs | array of paths | Files that must exist for the task to be considered up to date |
params | array of strings or tables | Named parameters: "name" (required), "name=value" (default) or { name, default, choices, desc } (guide) |
requires | array of strings | Variables that must be set and not empty (guide) |
vars | table | Named values: fixed, { sh = "command" } or { mq = "query", from = "file" }; ${NAME} refers to another (Variables) |
env | array of KEY=VALUE | Default environment variables |
dir | string | Working directory |
dotenv | array of paths | .env files to load (guide) |
alias | array of strings | Alternate names |
private | bool | Hide from listings |
imports | array of paths, globs or tables | Document-wide only: files to import; a table takes path, as, optional and flatten (Importing Tasks) |
Environment variables set for tasks: MX_ARGS, MX_ARG_<N>, MX_PARAM_<NAME>, MX_OUTPUT_<TASK>, vars entries as variables of their own name, and in loops MX_ITEM, MX_INDEX, MX_<AS> and MX_<AXIS>.
CLI
mq-task [OPTIONS] [TASK]... [-- <ARGS>...] [COMMAND]
Several tasks can be named: mq-task lint test runs them in that order as one run, so a dependency they share runs once. Arguments after -- belong to a single task, so they cannot be combined with several.
Commands
| Command | Description |
|---|---|
run | Run a task |
list | List tasks (-a/--all includes private; --json prints name, description, aliases, depends, params, private and languages as JSON) |
tui | Select and run a task interactively |
check | Look for mistakes without running anything (--strict, --json; see Checking a Task File) |
graph [TASK] | Print the dependency graph (--format text|mermaid) |
completions <SHELL> | Generate shell completions |
init | Write a starter tasks.md (-o for another path); init --config writes a sample mq-task.toml |
Options
| Option | Description |
|---|---|
-f, --file <FILE> | Markdown file (default: nearest tasks.md, else README.md; env MQ_TASK_FILE) |
-c, --config <CONFIG> | Configuration file (default: mq-task.toml next to the task file; env MQ_TASK_CONFIG) |
-r, --runtime <LANG:COMMAND> | Override a runtime |
-e, --execution-mode <MODE> | stdin, file or arg for overrides |
--lang <LANG> | Only run code blocks of this language |
-v, --verbose | Print each code block (and its directory) on stderr before it runs |
--dry-run | Show what would run |
--env <KEY=VALUE> | Set an environment variable (repeatable) |
-d, --dir <PATH> | Working directory |
--summary | Describe the task (description, dependencies, parameters, options) instead of running it |
--status | Say whether each task would run (up to date per status, or sources/outputs) without running anything; exit 1 when any would (details) |
--no-deps | Run only the named tasks, not their depends |
-q, --quiet | Print only task output and errors: no ▶, ↳ or ✔ lines |
--timings | Print how long each task took, and the totals, on stderr when the run ends |
-w, --watch | Re-run when sources, dotenv files or the task file change |
--interval <DURATION> | How often --watch checks for changes (default 300ms, minimum 50ms) |
--parallel | Run dependencies concurrently |
-j, --jobs <N> | Max concurrent tasks |
--output <MODE> | interleaved, prefixed or group (see Parallel Execution) |
-k, --keep-going | Continue independent tasks after a failure |
--no-cache | Ignore up-to-date checks (sources/outputs and status) |
-y, --yes | Answer yes to every prompt |
Exit codes
mq-task exits with the code of the task's process, so it composes with &&, CI and git hooks.
- A task killed by
timeoutexits with124. - A run ended by
SIGTERMorSIGHUPexits with128plus the signal number (143,129), as a shell reports it (details). - Under
--keep-going, the first failure's code is used. - Other errors (a bad task file, an unknown task, a declined prompt) exit with
1.
Which task failed
A failure names the task, and the loop item for for loops, so you do not have to guess from the output:
Error: Task exited with status code 4 (in task 'build', tasks.md:12)
Error: Task exited with status code 5 (in task 'each[b]', tasks.md:30)
Timeouts, missing parameters or variables and declined prompts already name the task in their own message.
Where it failed
When a code block fails, the message also gives the line of its fence in the task file, file:line, so a terminal or editor can jump to it. For an imported task that is the line in the imported file:
Error: Task exited with status code 3 (in task 'build', tasks.md:21)
In GitHub Actions the annotation mq-task prints carries the same file and line, so the error appears on that line of the Markdown in the pull request.
Signals
SIGINT (Ctrl+C) goes to the whole foreground process group, so the running task receives it directly. SIGTERM and SIGHUP (a CI cancel, kill, a closed terminal) reach only mq-task, so it stops the running task for you: first with SIGTERM (Ctrl+Break on Windows), and after 300 ms by force. Nothing new is started, but the task's defer tasks still run, and mq-task exits with 128 + signal.
On Windows each task that is cut off from the console (parallel runs, the TUI, timeout) runs in a Job Object, so stopping it also stops everything it started.