moon exec and moon run with the --query option.
Syntax
The query language uses a familiar SQL-inspired syntax that combines fields, comparison operators, and logical operators to build powerful filters.Comparisons
A comparison (also known as an assignment) is an expression that defines a piece of criteria. This criteria maps a field to a value with an explicit comparison operator.Equals, Not equals
The equals (=) and not equals (!=) comparison operators can be used for exact value matching.
Like, Not like
The like (~) and not like (!~) comparison operators can be used for wildcard value matching using glob syntax.
Like comparisons can only be used on non-enum fields (strings). They cannot be used on fields like
language, projectLayer, taskType, etc.Conditions
The&& and || logical operators can be used to combine multiple comparisons into a condition:
&&- Logical AND (all conditions must match)||- Logical OR (at least one condition must match)
AND or OR:
Grouping
For advanced queries and complex conditions, you can group comparisons using parentheses to create logical groupings. Groups can also be nested within other groups.Fields
The following fields can be used as criteria in your queries. These fields are related to task tokens.Project fields
language
Programming language the project is written in, as defined in moon.*.
bash, batch, javascript, typescript, rust, go, python, ruby, php, etc.
project
Name OR alias of the project.
projectAlias
Alias of the project. For example, the package.json name.
projectId
Name of the project, as defined in .moon/workspace.*, or id in moon.*.
projectLayer
The project layer, as defined in moon.*.
application, infrastructure, library, tool, unknown
projectSource
Relative file path from the workspace root to the project root, as defined in .moon/workspace.*.
projectStack
The project stack, as defined in moon.*.
backend, frontend, systems, infrastructure, unknown
tag
A tag within the project, as defined in moon.*.
Task fields
task
ID/name of a task within the project.
taskToolchain
The toolchain a task will run against, as defined in moon.*.
system, node, bun, deno, rust, go, python, etc.
taskType
The type of task, based on its configured settings.
build, run, test
Examples
Filter by language
Run tests for all JavaScript projects:Filter by project layer
Build all library projects:Combine multiple conditions
Run tests for TypeScript projects in the frontend stack:Use OR conditions
Build projects using either Node or Bun toolchains:Complex grouped queries
Run tests for React or Vue projects, but only in libraries:Pattern matching with globs
Run builds for all packages in a specific directory:Filter by task type
Run all build tasks across all projects:Query validation
When building queries, moon validates:- Empty queries - Queries must contain at least one comparison
- Unknown fields - All field names must be valid
- Unknown values - Enum fields must use valid values
- Operator mixing - Cannot mix
&&and||in the same condition without grouping - Like operators - Cannot use
~or!~on enum fields - Syntax errors - All queries must be syntactically valid
Implementation details
The query language is implemented using:- Parser - Uses the Pest parsing library with a custom grammar
- AST - Builds an abstract syntax tree from the parsed query
- Criteria builder - Converts the AST into structured criteria
- Query executor - Evaluates criteria against projects and tasks
Related
moon exec- Execute tasks with queriesmoon run- Run tasks with queries- Task tokens - Available token variables
- Targets - Task target syntax