0
# Advanced Commands
1
2
Advanced moon capabilities for workspace analysis, toolchain management, and debugging.
3
4
## Capabilities
5
6
### Workspace Query System
7
8
Query and analyze workspace information using flexible filter criteria.
9
10
```bash { .api }
11
/**
12
* Query projects using flexible filter criteria
13
* Supports complex logical expressions and patterns
14
*/
15
moon query projects <statement>
16
17
# Query Statement Syntax:
18
# Logical Operators:
19
# && AND operation
20
# || OR operation
21
# ! NOT operation
22
# () Grouping
23
24
# Filter Criteria:
25
# language=<lang> Programming language (javascript, typescript, rust, etc.)
26
# projectType=<type> Project type (application, library, tool, etc.)
27
# tag=<tag> Project tag
28
# project~<pattern> Project name pattern matching
29
# projectSource~<path> Source path pattern matching
30
# hasTask=<task> Projects that define specific task
31
# dependsOn=<project> Projects that depend on specified project
32
```
33
34
**Project Query Examples:**
35
36
```bash
37
# Find all TypeScript applications
38
moon query projects "language=typescript && projectType=application"
39
40
# Find projects with specific tag
41
moon query projects "tag=frontend"
42
43
# Find projects matching name pattern
44
moon query projects "project~*-api"
45
46
# Complex query with multiple criteria
47
moon query projects "(language=javascript || language=typescript) && projectType=library"
48
49
# Find projects in specific directory
50
moon query projects "projectSource~packages/*"
51
52
# Find projects with build task
53
moon query projects "hasTask=build"
54
55
# Find projects depending on shared library
56
moon query projects "dependsOn=shared-lib"
57
```
58
59
### Task Query System
60
61
Query tasks across the workspace using filter criteria.
62
63
```bash { .api }
64
/**
65
* Query tasks across projects using filter criteria
66
* Find tasks matching specific patterns or properties
67
*/
68
moon query tasks <statement>
69
70
# Task Query Criteria:
71
# task=<name> Task name
72
# project=<name> Project containing task
73
# platform=<platform> Target platform
74
# type=<type> Task type (build, test, lint, etc.)
75
# hasInput=<pattern> Tasks with input files matching pattern
76
# hasOutput=<pattern> Tasks with output files matching pattern
77
```
78
79
**Task Query Examples:**
80
81
```bash
82
# Find all build tasks
83
moon query tasks "task=build"
84
85
# Find test tasks in frontend projects
86
moon query tasks "type=test && project~*frontend*"
87
88
# Find tasks with TypeScript inputs
89
moon query tasks "hasInput=*.ts"
90
```
91
92
### Touched Files Analysis
93
94
Analyze which files have been modified and their impact on the workspace.
95
96
```bash { .api }
97
/**
98
* Query touched files and their relationships to projects/tasks
99
* Useful for understanding change impact in CI/CD pipelines
100
*/
101
moon query touched-files
102
103
# Output Information:
104
# - Modified files with change status
105
# - Affected projects based on file ownership
106
# - Impacted tasks that depend on changed files
107
# - Change status (added, modified, deleted, etc.)
108
```
109
110
### Toolchain Management
111
112
Manage development tools and their versions within the workspace.
113
114
```bash { .api }
115
/**
116
* Manage toolchain plugins and tool configurations
117
* Controls tool installation, versioning, and lifecycle
118
*/
119
moon toolchain <subcommand>
120
121
# Common Subcommands:
122
# list List all configured tools and their versions
123
# install <tool> Install a specific tool
124
# uninstall <tool> Uninstall a specific tool
125
# outdated Check for outdated tool versions
126
# sync Synchronize toolchain state
127
```
128
129
**Toolchain Examples:**
130
131
```bash
132
# List all configured tools
133
moon toolchain list
134
135
# Install Node.js toolchain
136
moon toolchain install node
137
138
# Check for outdated tools
139
moon toolchain outdated
140
141
# Sync toolchain state
142
moon toolchain sync
143
```
144
145
### Binary Path Resolution
146
147
Get absolute paths to tool binaries within the managed toolchain.
148
149
```bash { .api }
150
/**
151
* Return absolute path to a tool's binary within the toolchain
152
* Useful for scripting and IDE integration
153
*/
154
moon bin <tool>
155
156
# Arguments:
157
# <tool> Tool name (node, npm, cargo, tsc, etc.)
158
159
# Exit Codes:
160
# 0 Tool found, path printed to stdout
161
# 1+ Tool not configured or not installed
162
```
163
164
**Binary Path Examples:**
165
166
```bash
167
# Get Node.js binary path
168
moon bin node
169
# Output: /home/user/.moon/tools/node/18.17.0/bin/node
170
171
# Get TypeScript compiler path
172
moon bin tsc
173
# Output: /home/user/.moon/tools/node/18.17.0/node_modules/.bin/tsc
174
175
# Use in scripts
176
NODE_BIN=$(moon bin node)
177
$NODE_BIN --version
178
```
179
180
### Migration and Conversion
181
182
Migrate existing projects and configurations to moon.
183
184
```bash { .api }
185
/**
186
* Convert existing project configurations to moon format
187
* Supports migration from various build tools and package managers
188
*/
189
moon migrate <operation>
190
191
# Migration Operations:
192
# from-package-json Convert package.json scripts to moon tasks
193
# from-turborepo Migrate from Turborepo workspace configuration
194
195
# Options:
196
# --skip-touched-files-check Disable check for uncommitted changes
197
# --dry-run Preview changes without applying them
198
```
199
200
**Migration Examples:**
201
202
```bash
203
# Migrate from package.json scripts
204
moon migrate from-package-json
205
206
# Convert Turborepo configuration
207
moon migrate from-turborepo
208
209
# Preview migration without changes
210
moon migrate from-package-json --dry-run
211
```
212
213
### Docker Integration
214
215
Generate and manage Docker configurations for moon workspaces.
216
217
```bash { .api }
218
/**
219
* Generate Docker configurations optimized for moon workspaces
220
* Creates Dockerfiles and docker-compose files
221
*/
222
moon docker <subcommand>
223
224
# Subcommands:
225
# scaffold Generate Dockerfile and docker-compose configurations
226
# sync Update Docker configurations after workspace changes
227
# prune Remove unused Docker configurations
228
```
229
230
**Docker Examples:**
231
232
```bash
233
# Generate Docker configurations
234
moon docker scaffold
235
236
# Update configurations after changes
237
moon docker sync
238
239
# Clean up unused configurations
240
moon docker prune
241
```
242
243
### Debugging and Diagnostics
244
245
Debug moon internals and diagnose workspace issues.
246
247
```bash { .api }
248
/**
249
* Debug moon internals and workspace configuration
250
* Hidden command for troubleshooting and development
251
*/
252
moon debug <subcommand>
253
254
# Debug Subcommands:
255
# config Show resolved configuration
256
# cache Inspect cache contents and statistics
257
# graph Analyze dependency graphs
258
# env Display environment variables and context
259
# profile Performance profiling and analysis
260
```
261
262
**Debugging Examples:**
263
264
```bash
265
# Show resolved workspace configuration
266
moon debug config
267
268
# Inspect cache statistics
269
moon debug cache
270
271
# Analyze project dependency graph
272
moon debug graph
273
274
# Display environment context
275
moon debug env
276
```
277
278
### AI Integration (MCP)
279
280
Start Model Context Protocol server for AI agent integration.
281
282
```bash { .api }
283
/**
284
* Start MCP (Model Context Protocol) server for AI agent requests
285
* Enables AI agents to interact with moon workspaces
286
*/
287
moon mcp [subcommand]
288
289
# MCP Operations:
290
# start Start MCP server (default)
291
# stop Stop running MCP server
292
# status Check MCP server status
293
# config Configure MCP server settings
294
295
# Options:
296
# --port <port> Server port (default: auto-assigned)
297
# --host <host> Server host (default: localhost)
298
# --transport <type> Transport type (stdio, http, websocket)
299
```
300
301
**MCP Examples:**
302
303
```bash
304
# Start MCP server with default settings
305
moon mcp
306
307
# Start server on specific port
308
moon mcp start --port 3000
309
310
# Start with HTTP transport
311
moon mcp start --transport http
312
313
# Check server status
314
moon mcp status
315
```
316
317
## Advanced Usage Patterns
318
319
### Workspace Analysis Pipeline
320
321
```bash
322
# Comprehensive workspace analysis
323
moon query projects "language=typescript" --json | \
324
jq '.[] | .id' | \
325
xargs -I {} moon project {} --json | \
326
jq '.tasks | keys[]'
327
328
# Find affected projects and their tasks
329
moon query touched-files --json | \
330
jq '.affected_projects[]' | \
331
xargs -I {} moon run {}:build --affected
332
```
333
334
### CI/CD Integration
335
336
```bash
337
# Query for projects with specific CI requirements
338
moon query projects "hasTask=ci && projectType=application"
339
340
# Run only affected tests in CI
341
moon query touched-files | \
342
moon run :test --affected --stdin
343
344
# Generate deployment targets
345
moon query projects "tag=deployable" --json | \
346
jq -r '.[].id' | \
347
xargs -I {} moon run {}:deploy
348
```
349
350
### Developer Tooling
351
352
```bash
353
# Setup development environment
354
moon toolchain install node typescript
355
moon setup
356
moon sync hooks
357
358
# Validate workspace health
359
moon debug config
360
moon query projects "hasTask=lint" | xargs moon run
361
```
362
363
## Error Handling
364
365
Common advanced command scenarios and troubleshooting:
366
367
- **Query Syntax Errors**: Check logical operators and criteria spelling
368
- **Toolchain Issues**: Use `moon debug env` to check tool installation status
369
- **Migration Conflicts**: Use `--dry-run` to preview changes before applying
370
- **MCP Connection Issues**: Check firewall settings and port availability
371
- **Cache Problems**: Use `moon debug cache` to inspect cache state