@memberjunction/cli 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,944 +1,284 @@
1
1
  # @memberjunction/cli
2
2
 
3
- The official command-line interface (CLI) for MemberJunction, providing essential tools for installation, database management, code generation, AI operations, testing, and database documentation.
3
+ The official command-line interface for MemberJunction. Provides tools for installation, database migrations, code generation, metadata sync, AI operations, testing, database documentation, and query generation.
4
+
5
+ ## Architecture
6
+
7
+ ```mermaid
8
+ graph TD
9
+ subgraph "@memberjunction/cli (mj)"
10
+ A[CLI Entry Point] --> B[Commands]
11
+ B --> C[install]
12
+ B --> D[migrate]
13
+ B --> E[codegen]
14
+ B --> F[sync]
15
+ B --> G[ai]
16
+ B --> H[test]
17
+ B --> I[dbdoc]
18
+ B --> J[querygen]
19
+ B --> K[bump]
20
+ B --> L[clean]
21
+
22
+ A --> M[Hooks]
23
+ M --> N[init]
24
+ M --> O[prerun]
25
+ end
26
+
27
+ subgraph "Underlying Engines"
28
+ P["@memberjunction/codegen-lib"]
29
+ Q["@memberjunction/metadata-sync"]
30
+ R["@memberjunction/testing-cli"]
31
+ S["@memberjunction/db-auto-doc"]
32
+ T["@memberjunction/query-gen"]
33
+ U["@memberjunction/ai-cli"]
34
+ end
35
+
36
+ E --> P
37
+ F --> Q
38
+ H --> R
39
+ I --> S
40
+ J --> T
41
+ G --> U
42
+
43
+ style A fill:#2d6a9f,stroke:#1a4971,color:#fff
44
+ style C fill:#2d8659,stroke:#1a5c3a,color:#fff
45
+ style D fill:#2d8659,stroke:#1a5c3a,color:#fff
46
+ style E fill:#7c5295,stroke:#563a6b,color:#fff
47
+ style F fill:#7c5295,stroke:#563a6b,color:#fff
48
+ style G fill:#b8762f,stroke:#8a5722,color:#fff
49
+ style H fill:#b8762f,stroke:#8a5722,color:#fff
50
+ style I fill:#b8762f,stroke:#8a5722,color:#fff
51
+ style J fill:#b8762f,stroke:#8a5722,color:#fff
52
+ ```
4
53
 
5
54
  ## Overview
6
55
 
7
- The MemberJunction CLI (`mj`) is a comprehensive toolset designed to streamline the development and maintenance of MemberJunction applications. It handles everything from initial installation to ongoing database migrations, code generation, AI agent execution, testing, and automated database documentation.
56
+ The `mj` CLI is built on the oclif framework and acts as a unified entry point for all MemberJunction development tools. Each command group delegates to a specialized package.
8
57
 
9
58
  ## Installation
10
59
 
11
- ### Global Installation (Recommended)
12
60
  ```bash
61
+ # Global (recommended)
13
62
  npm install -g @memberjunction/cli
14
- ```
15
63
 
16
- ### Local Installation
17
- ```bash
64
+ # Local
18
65
  npm install --save-dev @memberjunction/cli
19
66
  ```
20
67
 
21
- ## Prerequisites
22
-
23
- - **Node.js**: Version 20.0.0 or higher
24
- - **SQL Server**: Access to a SQL Server instance for database operations
25
- - **Disk Space**: At least 2GB of free disk space for installation
68
+ **Requires Node.js 20.0.0 or higher.**
26
69
 
27
70
  ## Configuration
28
71
 
29
- The CLI uses a configuration file system powered by [cosmiconfig](https://github.com/davidtheclark/cosmiconfig). It searches for configuration in the following locations:
30
-
31
- - `.mjrc`
32
- - `.mjrc.json`
33
- - `.mjrc.yaml`
34
- - `.mjrc.yml`
35
- - `.mjrc.js`
36
- - `.mjrc.cjs`
37
- - `mj.config.js`
38
- - `mj.config.cjs`
39
- - `package.json` (in a `"mj"` property)
40
-
41
- ### Configuration Schema
42
-
43
- ```typescript
44
- interface MJConfig {
45
- dbHost: string; // Database server hostname (default: 'localhost')
46
- dbDatabase: string; // Database name
47
- dbPort: number; // Database port (default: 1433)
48
- codeGenLogin: string; // Database login for CodeGen operations
49
- codeGenPassword: string; // Database password for CodeGen operations
50
- migrationsLocation?: string; // Location of migration files (default: 'filesystem:./migrations')
51
- dbTrustServerCertificate?: boolean; // Trust server certificate (default: false)
52
- coreSchema?: string; // Core schema name (default: '__mj')
53
- cleanDisabled?: boolean; // Disable database cleaning (default: true)
54
- mjRepoUrl?: string; // MemberJunction repository URL
55
-
56
- // AI-specific settings (optional)
57
- aiSettings?: {
58
- defaultTimeout?: number; // Default timeout for AI operations (default: 300000ms)
59
- outputFormat?: 'compact' | 'json' | 'table'; // Default output format
60
- logLevel?: 'info' | 'debug' | 'verbose'; // Logging detail level
61
- enableChat?: boolean; // Enable chat features (default: true)
62
- chatHistoryLimit?: number; // Chat history size limit
63
- };
64
- }
65
- ```
72
+ Uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) to find configuration:
66
73
 
67
- ### Example Configuration
68
-
69
- ```javascript
70
- // mj.config.cjs
71
- module.exports = {
72
- dbHost: 'localhost',
73
- dbDatabase: 'MemberJunction',
74
- dbPort: 1433,
75
- codeGenLogin: 'sa',
76
- codeGenPassword: 'YourPassword123!',
77
- dbTrustServerCertificate: true,
78
- coreSchema: '__mj'
79
- };
80
- ```
74
+ - `mj.config.js` / `mj.config.cjs`
75
+ - `.mjrc` / `.mjrc.json` / `.mjrc.yaml`
76
+ - `package.json` (in `"mj"` property)
81
77
 
82
78
  ## Commands
83
79
 
84
- ### Core Commands
85
-
86
- #### `mj install`
80
+ ### mj install
87
81
 
88
- Performs a complete installation of MemberJunction, including:
89
- - Database setup
90
- - Generated entities configuration
91
- - API server configuration
92
- - Explorer UI configuration
82
+ Interactive installer for new MemberJunction environments.
93
83
 
94
84
  ```bash
95
- mj install [--verbose]
85
+ mj install
96
86
  ```
97
87
 
98
- The install command will:
99
- 1. Verify Node.js version and disk space requirements
100
- 2. Check for required directories (GeneratedEntities, SQL Scripts, MJAPI, MJExplorer)
101
- 3. Prompt for configuration values or read from `install.config.json`
102
- 4. Create `.env` files with database and authentication settings
103
- 5. Run npm installations and link packages
104
- 6. Execute CodeGen to generate initial code
88
+ Sets up the database schema, applies migrations, and generates initial code.
105
89
 
106
- #### `mj codegen`
90
+ ### mj migrate
107
91
 
108
- Runs the MemberJunction code generation process to create TypeScript entities and metadata from your database schema.
92
+ Run Flyway database migrations.
109
93
 
110
94
  ```bash
111
- mj codegen [--skipdb]
95
+ mj migrate
96
+ mj migrate [--verbose] [--tag <version>] [--schema <name>] [--dir <path>]
112
97
  ```
113
98
 
114
99
  Options:
115
- - `--skipdb`: Skip database migration before running code generation
116
-
117
- #### `mj codegen manifest`
118
-
119
- Generates a class registrations manifest to prevent tree-shaking of `@RegisterClass` decorated classes. The tool walks the app's transitive dependency tree and produces a tailored import manifest.
120
-
121
- ```bash
122
- mj codegen manifest [--output <path>] [--appDir <path>] [--filter <class>] [--quiet]
123
- ```
100
+ - `-v, --verbose`: Enable detailed logging
101
+ - `-t, --tag <version>`: Specify a version tag for migrations (e.g., 'v2.10.0')
102
+ - `-s, --schema <name>`: Target schema (overrides `coreSchema` from config)
103
+ - `--dir <path>`: Migration source directory (overrides `migrationsLocation` from config)
124
104
 
125
- Options:
126
- - `--output, -o <path>`: Output manifest file path (default: `./src/generated/class-registrations-manifest.ts`)
127
- - `--appDir, -a <path>`: App directory containing `package.json` (default: current directory)
128
- - `--filter, -f <class>`: Only include classes with this base class (can be repeated)
129
- - `--quiet, -q`: Suppress progress output
105
+ **Schema Handling:**
106
+ - When using `--schema`, the specified schema will be automatically created if it doesn't exist
107
+ - This enables migrating to new schemas without manual DDL setup
108
+ - The schema creation uses Flyway's `createSchemas` feature
130
109
 
131
110
  Examples:
132
111
  ```bash
133
- # Generate manifest for the current app
134
- mj codegen manifest --output ./src/generated/class-registrations-manifest.ts
112
+ # Basic migration
113
+ mj migrate
135
114
 
136
- # Generate for a specific app directory
137
- mj codegen manifest --appDir ./packages/MJAPI --output ./packages/MJAPI/src/generated/class-registrations-manifest.ts
115
+ # Migrate to a specific version tag
116
+ mj migrate --tag v2.10.0
138
117
 
139
- # Only include engine and action classes
140
- mj codegen manifest --filter BaseEngine --filter BaseAction
141
- ```
118
+ # Migrate a custom schema with custom migrations directory
119
+ mj migrate --schema __BCSaaS --dir ./migrations/v1
142
120
 
143
- The generated manifest imports all packages in the app's dependency tree that contain `@RegisterClass` decorators, ensuring the class factory system works correctly even with aggressive tree-shaking. See the [CodeGenLib README](../CodeGenLib/README.md) for programmatic usage.
144
-
145
- #### `mj migrate`
146
-
147
- Applies database migrations to update your MemberJunction schema to the latest version.
148
-
149
- ```bash
150
- mj migrate [--verbose] [--tag <version>]
121
+ # Verbose output for debugging
122
+ mj migrate --verbose
151
123
  ```
152
124
 
153
- Options:
154
- - `--verbose`: Enable detailed logging
155
- - `--tag <version>`: Specify a version tag for migrations (e.g., 'v2.10.0')
156
-
157
- #### `mj bump`
125
+ ### mj codegen
158
126
 
159
- Updates all @memberjunction/* package dependencies to a specified version.
127
+ Run MemberJunction code generation.
160
128
 
161
129
  ```bash
162
- mj bump [--recursive] [--dry] [--quiet] [--tag <version>] [--verbose]
163
- ```
164
-
165
- Options:
166
- - `-r, --recursive`: Update dependencies in all subdirectories
167
- - `-d, --dry`: Preview changes without writing to files
168
- - `-q, --quiet`: Only output paths of updated packages
169
- - `-t, --tag <version>`: Target version (defaults to CLI version)
170
- - `-v, --verbose`: Enable detailed logging
171
-
172
- Example - Update all packages recursively and run npm install:
173
- ```bash
174
- mj bump -rqt v2.10.0 | xargs -n1 -I{} npm install --prefix {}
175
- ```
130
+ # Run full code generation
131
+ mj codegen
176
132
 
177
- #### `mj clean`
178
-
179
- Resets the MemberJunction database to a pre-installation state. **Use with caution!**
180
-
181
- ```bash
182
- mj clean [--verbose]
133
+ # Generate class registration manifests only
134
+ mj codegen manifest
135
+ mj codegen manifest --exclude-packages @memberjunction --output ./src/generated/manifest.ts
183
136
  ```
184
137
 
185
- Note: This command is disabled by default. Set `cleanDisabled: false` in your configuration to enable it.
186
-
187
- ---
188
-
189
- ### `mj sync` - Metadata Synchronization
138
+ ### mj sync
190
139
 
191
- Manages MemberJunction metadata synchronization between database and local files. This suite of commands enables version control, IDE-based editing, and CI/CD integration for MJ metadata.
140
+ Metadata synchronization between JSON files and the database.
192
141
 
193
142
  ```bash
194
- mj sync [COMMAND] [OPTIONS]
195
- ```
143
+ # Initialize metadata directory
144
+ mj sync init
196
145
 
197
- Available sync commands:
198
- - `validate` - Validate metadata files for correctness
199
- - `init` - Initialize a directory for metadata sync
200
- - `pull` - Pull metadata from database to local files
201
- - `push` - Push local file changes to database
202
- - `status` - Show status of local vs database metadata
203
- - `watch` - Watch for changes and auto-sync
204
- - `file-reset` - Reset file checksums after manual edits
205
-
206
- **📚 For detailed documentation:** See the [MetadataSync README](../MetadataSync/README.md)
207
-
208
- #### Adding Comments to JSON Metadata Files
209
-
210
- Since JSON doesn't support comments natively, you can add documentation to your metadata files using custom keys with an underscore prefix. These keys are preserved but ignored during sync operations:
211
-
212
- ```json
213
- {
214
- "_comments": [
215
- "This file configures encryption for sensitive fields",
216
- "See /metadata/encryption-keys/ for key configuration"
217
- ],
218
- "fields": {
219
- "Name": "My Entity",
220
- "Encrypt": true
221
- },
222
- "_note": "Comments can appear anywhere in the record"
223
- }
224
- ```
146
+ # Check sync status
147
+ mj sync status
225
148
 
226
- **Key points:**
227
- - Use underscore prefix (`_comments`, `_note`, etc.) by convention
228
- - Comments are preserved in their original position after sync operations
229
- - Reserved keys: `fields`, `relatedEntities`, `primaryKey`, `sync`, `deleteRecord`
149
+ # Pull metadata from database to files
150
+ mj sync pull
230
151
 
231
- See the [MetadataSync README](../MetadataSync/README.md#adding-comments-to-json-metadata-files) for complete documentation.
152
+ # Push metadata from files to database
153
+ mj sync push
232
154
 
233
- #### Quick Examples:
234
- ```bash
235
- # Validate all metadata files
155
+ # Validate metadata files
236
156
  mj sync validate
237
157
 
238
- # Pull AI Prompts from database
239
- mj sync pull --entity="AI Prompts"
240
-
241
- # Push changes to database
242
- mj sync push
243
-
244
- # Watch for changes
158
+ # Watch for file changes
245
159
  mj sync watch
246
- ```
247
-
248
- ---
249
160
 
250
- ### `mj ai` - AI Operations
251
-
252
- Execute AI agents and actions using MemberJunction's AI framework. This command provides access to 20+ AI agents and 30+ actions for various tasks.
253
-
254
- ```bash
255
- mj ai [COMMAND] [OPTIONS]
161
+ # Reset file state
162
+ mj sync file-reset
256
163
  ```
257
164
 
258
- Available AI commands:
259
- - `agents list` - List available AI agents
260
- - `agents run` - Execute an AI agent with a prompt or start interactive chat
261
- - `actions list` - List available AI actions
262
- - `actions run` - Execute an AI action with parameters
263
- - `prompts list` - List available AI models for direct prompt execution
264
- - `prompts run` - Execute a direct prompt with an AI model
265
- - `audit agent-run` - Audit and analyze AI agent execution runs for debugging
165
+ ### mj ai
266
166
 
267
- **📚 For detailed documentation:** See the [AI-CLI README](../AI/AICLI/README.md)
268
-
269
- #### Quick Examples:
167
+ AI-powered operations.
270
168
 
271
169
  ```bash
272
- # List all available agents
273
- mj ai agents list
274
-
275
- # Execute an agent with a prompt
276
- mj ai agents run -a "Skip: Requirements Expert" -p "Create a dashboard for sales metrics"
277
-
278
- # Start interactive chat with an agent
279
- mj ai agents run -a "Child Component Generator Sub-agent" --chat
280
-
281
- # List all available actions
282
- mj ai actions list --output=table
283
-
284
- # Execute an action with parameters
285
- mj ai actions run -n "Get Weather" --param "Location=Boston"
286
-
287
- # Execute action with multiple parameters
288
- mj ai actions run -n "Send Single Message" \
289
- --param "To=user@example.com" \
290
- --param "Subject=Test Message" \
291
- --param "Body=Hello from MJ CLI"
292
-
293
- # Validate action without executing
294
- mj ai actions run -n "Calculate Expression" --param "Expression=2+2*3" --dry-run
295
-
296
- # List available AI models
297
- mj ai prompts list
298
-
299
- # Execute a direct prompt
300
- mj ai prompts run -p "Explain quantum computing in simple terms"
301
-
302
- # Use a specific model
303
- mj ai prompts run -p "Write a Python function to sort a list" --model "gpt-4"
304
-
305
- # Audit recent agent runs
306
- mj ai audit agent-run --list --status failed --days 7
307
-
308
- # Audit specific run with summary
309
- mj ai audit agent-run <run-id>
310
-
311
- # Examine specific step in detail
312
- mj ai audit agent-run <run-id> --step 3 --detail full
313
-
314
- # Analyze errors in a run
315
- mj ai audit agent-run <run-id> --errors
316
-
317
- # Export full audit data
318
- mj ai audit agent-run <run-id> --export full --file audit.json
319
-
320
- # Use system prompt and temperature
321
- mj ai prompts run -p "Generate a haiku" --system "You are a poet" --temperature 0.3
322
- ```
323
-
324
- #### AI Command Options:
325
-
326
- **Agent Commands:**
327
- - `-a, --agent <name>`: Agent name (required)
328
- - `-p, --prompt <text>`: Prompt to execute
329
- - `-c, --chat`: Start interactive chat mode
330
- - `-o, --output <format>`: Output format (compact, json, table)
331
- - `-v, --verbose`: Show detailed execution information
332
- - `--timeout <ms>`: Execution timeout in milliseconds (default: 300000)
333
-
334
- **Action Commands:**
335
- - `-n, --name <name>`: Action name (required)
336
- - `-p, --param <key=value>`: Action parameters (can be specified multiple times)
337
- - `--dry-run`: Validate without executing
338
- - `-o, --output <format>`: Output format (compact, json, table)
339
- - `-v, --verbose`: Show detailed execution information
340
- - `--timeout <ms>`: Execution timeout in milliseconds (default: 300000)
341
-
342
- **Prompt Commands:**
343
- - `-p, --prompt <text>`: The prompt to execute (required)
344
- - `-m, --model <name>`: AI model to use (e.g., gpt-4, claude-3-opus)
345
- - `-s, --system <text>`: System prompt to set context
346
- - `-t, --temperature <0.0-2.0>`: Temperature for response creativity
347
- - `--max-tokens <number>`: Maximum tokens for the response
348
- - `-c, --configuration <id>`: AI Configuration ID to use
349
- - `-o, --output <format>`: Output format (compact, json, table)
350
- - `-v, --verbose`: Show detailed execution information
351
- - `--timeout <ms>`: Execution timeout in milliseconds (default: 300000)
352
-
353
- **Audit Commands:**
354
- - `<run-id>`: Agent Run ID (UUID) to audit (optional for --list mode)
355
- - `-l, --list`: List recent agent runs (filter with other options)
356
- - `-a, --agent <name>`: Filter by agent name (requires --list)
357
- - `--status <status>`: Filter by status: success, failed, running, all (default: all)
358
- - `--days <number>`: Number of days to look back (default: 7)
359
- - `--limit <number>`: Maximum runs to return (default: 50)
360
- - `-s, --step <number>`: Show details for specific step (1-based index)
361
- - `-d, --detail <level>`: Detail level for step: minimal, standard, detailed, full (default: standard)
362
- - `-e, --errors`: Show only error details and context
363
- - `--export <type>`: Export data: full, summary, steps
364
- - `-f, --file <path>`: Output file path for export
365
- - `--max-tokens <number>`: Max tokens per field (default: 5000, 0 = no limit)
366
- - `-o, --output <format>`: Output format (compact, json, table, markdown)
367
- - `-v, --verbose`: Show detailed diagnostic information
368
-
369
- #### AI Features:
370
-
371
- **Progress Tracking**: Real-time visual progress indicators during agent execution
372
- - Compact single-line progress in normal mode
373
- - Detailed progress with metadata in verbose mode
374
- - Visual icons for each execution phase (🚀 initialization, ✓ validation, 💭 execution, etc.)
375
-
376
- **Text Formatting**: Automatic formatting of long AI responses for better readability
377
- - Word wrapping at console width
378
- - Paragraph and list preservation
379
- - Code block highlighting
380
- - JSON syntax coloring
381
-
382
- **Interactive Chat**: Full conversation context maintained across messages
383
- - Agent remembers previous exchanges
384
- - Natural back-and-forth dialogue
385
- - Exit with "exit", "quit", or Ctrl+C
386
-
387
- **Agent Run Auditing**: Comprehensive debugging and analysis tools
388
- - List recent runs with filtering by agent, status, and date
389
- - View run summaries with performance metrics and step breakdowns
390
- - Deep dive into specific steps with smart truncation for large payloads
391
- - Automatic error pattern detection with suggested fixes
392
- - Multiple output formats including markdown for AI assistants
393
- - Export capabilities for offline analysis
394
- - Optimized for read-only performance with `simple` result type
395
-
396
- #### AI Configuration:
397
-
398
- Add AI-specific settings to your `mj.config.cjs`:
399
-
400
- ```javascript
401
- module.exports = {
402
- // Existing database settings...
403
-
404
- aiSettings: {
405
- defaultTimeout: 300000,
406
- outputFormat: 'compact',
407
- logLevel: 'info',
408
- enableChat: true,
409
- chatHistoryLimit: 10
410
- }
411
- };
412
- ```
413
-
414
- Execution logs are stored in `.mj-ai/logs/` for debugging and audit purposes.
415
-
416
- ---
417
-
418
- ### `mj test` - Testing Framework
419
-
420
- Execute and manage tests using MemberJunction's comprehensive testing framework. Run database-driven tests, test suites, and view execution history.
421
-
422
- ```bash
423
- mj test [COMMAND] [OPTIONS]
170
+ mj ai
424
171
  ```
425
172
 
426
- Available test commands:
427
- - `run` - Execute a single test by ID or name
428
- - `suite` - Execute a test suite
429
- - `list` - List available tests, suites, and types
430
- - `validate` - Validate test definitions without executing
431
- - `history` - View test execution history
432
- - `compare` - Compare test runs for regression detection
173
+ ### mj test
433
174
 
434
- **📚 For detailed documentation:** See the [Testing CLI README](../TestingFramework/CLI/README.md)
435
-
436
- #### Quick Examples:
175
+ Testing framework operations (delegates to `@memberjunction/testing-cli`).
437
176
 
438
177
  ```bash
439
- # Run a single test
440
- mj test run <test-id>
441
-
442
- # Run a test by name
443
- mj test run --name="Active Members Count"
178
+ # Run a test
179
+ mj test run --name "My Test"
444
180
 
445
- # Run a test suite
446
- mj test suite <suite-id>
181
+ # Run a suite
182
+ mj test suite --name "My Suite"
447
183
 
448
- # Run suite by name
449
- mj test suite --name="Agent Quality Suite"
450
-
451
- # List all tests
184
+ # List tests
452
185
  mj test list
453
186
 
454
- # List test suites
455
- mj test list --suites
456
-
457
- # List test types
458
- mj test list --types
187
+ # View history
188
+ mj test history --name "My Test"
459
189
 
460
- # Filter by test type
461
- mj test list --type=agent-eval
190
+ # Compare runs
191
+ mj test compare --run1 id1 --run2 id2
462
192
 
463
- # Validate all tests
464
- mj test validate --all
465
-
466
- # Validate specific test type
467
- mj test validate --type=agent-eval
468
-
469
- # View test execution history
470
- mj test history --test=<test-id>
471
-
472
- # Compare two test runs
473
- mj test compare <run-id-1> <run-id-2>
474
-
475
- # Output formats
476
- mj test run <test-id> --format=json --output=results.json
477
- mj test suite <suite-id> --format=markdown --output=report.md
478
- ```
479
-
480
- #### Test Command Options:
481
-
482
- **Run Command:**
483
- - `<testId>`: Test ID to execute
484
- - `-n, --name <name>`: Test name to execute
485
- - `-e, --environment <env>`: Environment context (dev, staging, prod)
486
- - `-f, --format <format>`: Output format (console, json, markdown)
487
- - `-o, --output <path>`: Output file path
488
- - `--dry-run`: Validate without executing
489
- - `-v, --verbose`: Show detailed execution information
490
-
491
- **Suite Command:**
492
- - `<suiteId>`: Test suite ID to execute
493
- - `-n, --name <name>`: Test suite name to execute
494
- - `-f, --format <format>`: Output format (console, json, markdown)
495
- - `-o, --output <path>`: Output file path
496
- - `-v, --verbose`: Show detailed execution information
497
-
498
- **List Command:**
499
- - `--suites`: List test suites instead of tests
500
- - `--types`: List test types
501
- - `-t, --type <type>`: Filter by test type
502
- - `--tag <tag>`: Filter by tag
503
- - `-s, --status <status>`: Filter by status
504
- - `-f, --format <format>`: Output format (console, json, markdown)
505
- - `-v, --verbose`: Show detailed information
506
-
507
- **Validate Command:**
508
- - `<testId>`: Test ID to validate
509
- - `-a, --all`: Validate all tests
510
- - `-t, --type <type>`: Validate tests by type
511
- - `--save-report`: Save validation report to file
512
- - `-f, --format <format>`: Output format (console, json, markdown)
513
- - `-o, --output <path>`: Output file path
514
- - `-v, --verbose`: Show detailed information
515
-
516
- **History Command:**
517
- - `-t, --test <id>`: Filter by test ID
518
- - `-r, --recent <n>`: Number of recent runs to show
519
- - `--from <date>`: Show history from date (YYYY-MM-DD)
520
- - `-s, --status <status>`: Filter by status
521
- - `-f, --format <format>`: Output format (console, json, markdown)
522
- - `-o, --output <path>`: Output file path
523
- - `-v, --verbose`: Show detailed information
524
-
525
- **Compare Command:**
526
- - `<runId1>`: First test run ID to compare
527
- - `<runId2>`: Second test run ID to compare
528
- - `-v, --version <versions>`: Compare runs by version
529
- - `-c, --commit <commits>`: Compare runs by git commit
530
- - `--diff-only`: Show only differences
531
- - `-f, --format <format>`: Output format (console, json, markdown)
532
- - `-o, --output <path>`: Output file path
533
- - `--verbose`: Show detailed information
534
-
535
- ---
536
-
537
- ### `mj dbdoc` - Database Documentation
538
-
539
- AI-powered database documentation generator for SQL Server, MySQL, and PostgreSQL. Analyzes your database structure, uses AI to generate comprehensive descriptions, and saves them as database metadata.
540
-
541
- ```bash
542
- mj dbdoc [COMMAND] [OPTIONS]
193
+ # Validate test config
194
+ mj test validate --name "My Test"
543
195
  ```
544
196
 
545
- Available dbdoc commands:
546
- - `init` - Initialize a new DBAutoDoc project
547
- - `analyze` - Analyze database and generate documentation
548
- - `generate-queries` - Generate sample SQL queries from existing analysis state
549
- - `export` - Export documentation in multiple formats (SQL, Markdown, HTML, CSV, Mermaid)
550
- - `export-sample-queries` - Export sample queries to MemberJunction metadata format
551
- - `status` - Show analysis status and progress
552
- - `reset` - Reset analysis state
197
+ ### mj dbdoc
553
198
 
554
- **📚 For detailed documentation:** See the [DBAutoDoc README](../DBAutoDoc/README.md)
555
-
556
- #### Quick Examples:
199
+ Database documentation generation.
557
200
 
558
201
  ```bash
559
- # Initialize new project (interactive wizard)
202
+ # Initialize documentation
560
203
  mj dbdoc init
561
204
 
562
- # Analyze database
205
+ # Analyze database schema
563
206
  mj dbdoc analyze
564
207
 
565
- # Resume from existing state
566
- mj dbdoc analyze --resume ./output/run-6/state.json
567
-
568
- # Use custom config
569
- mj dbdoc analyze --config ./my-config.json
570
-
571
- # Generate sample SQL queries from existing state
572
- mj dbdoc generate-queries --from-state ./output/run-1/state.json
573
-
574
- # Generate with custom settings
575
- mj dbdoc generate-queries --from-state ./output/run-1/state.json \
576
- --queries-per-table 10 \
577
- --output-dir ./queries
578
-
579
- # Export sample queries to MemberJunction metadata format
580
- mj dbdoc export-sample-queries \
581
- --input ./output/sample-queries.json \
582
- --output ./metadata/queries/.queries.json
583
-
584
- # Export with separate SQL files and category
585
- mj dbdoc export-sample-queries \
586
- --input ./output/sample-queries.json \
587
- --output ./metadata/queries/.queries.json \
588
- --separate-sql-files \
589
- --category "Database Documentation" \
590
- --min-confidence 0.8
591
-
592
- # Export all formats
593
- mj dbdoc export --sql --markdown --html --csv --mermaid
594
-
595
- # Export specific state file
596
- mj dbdoc export --state-file ./output/run-6/state.json --sql --markdown
597
-
598
- # Apply SQL directly to database
599
- mj dbdoc export --sql --apply
600
-
601
- # Export with filtering
602
- mj dbdoc export --approved-only --confidence-threshold 0.8
208
+ # Export documentation
209
+ mj dbdoc export
603
210
 
604
211
  # Check status
605
212
  mj dbdoc status
606
213
 
607
- # Reset state
608
- mj dbdoc reset --force
609
- ```
214
+ # Reset documentation
215
+ mj dbdoc reset
610
216
 
611
- #### DBAutoDoc Command Options:
612
-
613
- **Init Command:**
614
- - Interactive wizard guides you through:
615
- - Database connection configuration
616
- - AI provider setup (OpenAI, Anthropic, Google, Groq)
617
- - Resource limits and guardrails
618
- - Optional seed context for better analysis
619
-
620
- **Analyze Command:**
621
- - `-r, --resume <path>`: Resume from an existing state file
622
- - `-c, --config <path>`: Path to config file (default: ./config.json)
623
-
624
- **Generate Queries Command:**
625
- - `--from-state <path>`: Path to existing state.json file from previous analysis (required)
626
- - `--output-dir <path>`: Output directory for generated queries (optional)
627
- - `-c, --config <path>`: Path to config file for database connection and AI settings (default: ./config.json)
628
- - `--queries-per-table <number>`: Number of queries to generate per table (optional, overrides config)
629
- - `--max-execution-time <ms>`: Maximum execution time for query validation in milliseconds (optional, overrides config)
630
-
631
- **Export Sample Queries Command:**
632
- - `-i, --input <path>`: Path to sample-queries.json file from generate-queries (required)
633
- - `-o, --output <path>`: Output path for the .queries.json metadata file (required)
634
- - `--separate-sql-files`: Write SQL to separate files and use @file: references
635
- - `--sql-dir <name>`: Directory for SQL files when using --separate-sql-files (default: SQL)
636
- - `--category <name>`: Category name for @lookup reference (e.g., "Database Documentation")
637
- - `--status <value>`: Status to assign (Approved/Pending/Rejected/Expired, default: Pending)
638
- - `--min-confidence <value>`: Minimum confidence threshold to export (0-1, default: 0)
639
- - `--validated-only`: Only export queries that were successfully validated
640
- - `--append`: Append to existing metadata file instead of overwriting
641
- - `--include-primary-key`: Include primaryKey and sync fields (for updating existing records)
642
-
643
- **Export Command:**
644
- - `-s, --state-file <path>`: Path to state JSON file
645
- - `-o, --output-dir <path>`: Output directory for generated files
646
- - `--sql`: Generate SQL script with database-specific metadata statements
647
- - `--markdown`: Generate Markdown documentation with ERD diagrams
648
- - `--html`: Generate interactive HTML documentation
649
- - `--csv`: Generate CSV exports (tables.csv and columns.csv)
650
- - `--mermaid`: Generate Mermaid ERD diagram files (.mmd and .html)
651
- - `--report`: Generate analysis report with metrics
652
- - `--apply`: Apply SQL script directly to database
653
- - `--approved-only`: Only export approved items
654
- - `--confidence-threshold <value>`: Minimum confidence threshold (default: 0)
655
-
656
- **Status Command:**
657
- - `-s, --state-file <path>`: Path to state JSON file
658
-
659
- **Reset Command:**
660
- - `-f, --force`: Force reset without confirmation
661
-
662
- #### DBAutoDoc Features:
663
-
664
- **Core Capabilities:**
665
- - 🤖 **AI-Powered Analysis** - Uses OpenAI, Anthropic, Google, or Groq
666
- - 🔄 **Iterative Refinement** - Multi-pass analysis with backpropagation
667
- - 📊 **Topological Processing** - Analyzes tables in dependency order
668
- - 📈 **Data-Driven** - Leverages cardinality, statistics, and sample data
669
- - 🎯 **Convergence Detection** - Automatically knows when analysis is complete
670
- - 💾 **State Tracking** - Full audit trail of all iterations
671
- - 🔌 **Standalone** - Works with ANY database, no MemberJunction required
672
-
673
- **Multi-Database Support:**
674
- - SQL Server (extended properties)
675
- - PostgreSQL (COMMENT syntax)
676
- - MySQL (column/table comments)
677
-
678
- **Advanced Features:**
679
- - 🔍 **Relationship Discovery** - Detect missing primary and foreign keys
680
- - 🎯 **Sample Query Generation** - Generate reference SQL queries for AI agent training with alignment tracking
681
- - 🛡️ **Granular Guardrails** - Multi-level resource controls
682
- - ⏸️ **Resume Capability** - Pause and resume from checkpoint
683
- - 📦 **Programmatic API** - Use as a library in your applications
684
-
685
- **Output Formats:**
686
- - SQL Scripts (database-specific metadata)
687
- - Markdown Documentation (human-readable with ERD)
688
- - HTML Documentation (interactive, searchable)
689
- - CSV Exports (spreadsheet-ready)
690
- - Mermaid Diagrams (standalone ERD files)
691
- - Analysis Reports (detailed metrics)
692
- - Sample Queries (JSON with SQL, metadata, and alignment tracking)
693
-
694
- **Sample Query Generation:**
695
-
696
- DBAutoDoc can generate reference SQL queries that solve the **query alignment problem** where multi-query patterns (summary + detail) have inconsistent filtering logic. These "gold standard" queries include:
697
- - Explicit filtering rules for consistency
698
- - Alignment tracking via `relatedQueryIds`
699
- - Query patterns (Summary+Detail, Multi-Entity Drilldown, Time Series)
700
- - Validated, executable SQL
701
- - Perfect for few-shot prompting in AI agents like Skip
702
-
703
- Enable in config:
704
- ```json
705
- {
706
- "analysis": {
707
- "sampleQueryGeneration": {
708
- "enabled": true,
709
- "queriesPerTable": 5,
710
- "includeMultiQueryPatterns": true,
711
- "validateAlignment": true
712
- }
713
- }
714
- }
217
+ # Generate sample queries
218
+ mj dbdoc generate-queries
219
+ mj dbdoc export-sample-queries
715
220
  ```
716
221
 
717
- Or generate separately from existing state:
718
- ```bash
719
- mj dbdoc generate-queries --from-state ./output/run-1/state.json
720
- ```
721
-
722
- **Export to MemberJunction Metadata:**
723
-
724
- Transform generated queries into MemberJunction's Query entity format for use with AI agents like Skip:
725
- ```bash
726
- mj dbdoc export-sample-queries \
727
- --input ./output/sample-queries.json \
728
- --output ./metadata/queries/.queries.json \
729
- --category "Database Documentation" \
730
- --separate-sql-files
731
-
732
- # Then sync to database
733
- mj sync push ./metadata/queries/
734
- ```
735
-
736
- **Use Cases:**
737
- - Training AI agents to generate consistent multi-query patterns
738
- - Creating reference examples for few-shot prompting
739
- - Documenting common query patterns for your database
740
- - Validating that related queries use consistent filtering logic
741
- - Syncing generated queries to MemberJunction's Query entity for use by Skip
742
-
743
- ---
744
-
745
- ### `mj querygen` - AI-Powered SQL Query Generation
222
+ ### mj querygen
746
223
 
747
- Generate domain-specific SQL query templates using artificial intelligence. QueryGen analyzes your database schema, generates business questions, creates SQL queries with Nunjucks templates, tests them, and exports to metadata format.
224
+ Query generation tools.
748
225
 
749
226
  ```bash
750
- mj querygen [COMMAND] [OPTIONS]
751
- ```
752
-
753
- Available querygen commands:
754
- - `generate` - Generate SQL query templates for entities using AI
755
- - `validate` - Validate existing query templates
756
- - `export` - Export queries from database to metadata files
757
-
758
- **📚 For detailed documentation:** See the [QueryGen README](../QueryGen/README.md)
759
-
760
- #### Quick Examples:
761
-
762
- ```bash
763
- # Generate queries for all entities
764
227
  mj querygen generate
765
-
766
- # Generate for specific entities with verbose output
767
- mj querygen generate --entities "Customers,Orders" --verbose
768
-
769
- # Control entity grouping and refinement
770
- mj querygen generate --max-entities 2 --max-refinements 3
771
-
772
- # Export to specific directory
773
- mj querygen generate --output ./metadata/queries
774
-
775
- # Choose output mode
776
- mj querygen generate --mode database # Write directly to database
777
- mj querygen generate --mode both # Both metadata and database
778
-
779
- # Validate existing queries
780
- mj querygen validate
781
-
782
- # Validate specific directory
783
- mj querygen validate --path ./metadata/queries --verbose
784
-
785
- # Export queries from database to metadata
786
228
  mj querygen export
787
-
788
- # Export to custom location
789
- mj querygen export --output ./exported-queries --verbose
790
- ```
791
-
792
- #### QueryGen Command Options:
793
-
794
- **Generate Command:**
795
- - `-e, --entities <value>`: Specific entities to generate queries for (comma-separated)
796
- - `-x, --exclude-entities <value>`: Entities to exclude (comma-separated)
797
- - `-s, --exclude-schemas <value>`: Schemas to exclude (comma-separated)
798
- - `-m, --max-entities <value>`: Max entities per group (default: 3)
799
- - `-r, --max-refinements <value>`: Max refinement iterations (default: 3)
800
- - `-f, --max-fixes <value>`: Max error-fixing attempts (default: 5)
801
- - `--model <value>`: Preferred AI model
802
- - `--vendor <value>`: Preferred AI vendor
803
- - `-o, --output <value>`: Output directory (default: ./metadata/queries)
804
- - `--mode <option>`: Output mode: metadata|database|both (default: metadata)
805
- - `-v, --verbose`: Verbose output
806
-
807
- **Validate Command:**
808
- - `-p, --path <value>`: Path to queries metadata file or directory (default: ./metadata/queries)
809
- - `-v, --verbose`: Verbose output
810
-
811
- **Export Command:**
812
- - `-o, --output <value>`: Output directory (default: ./metadata/queries)
813
- - `-v, --verbose`: Verbose output
814
-
815
- #### QueryGen Features:
816
-
817
- **11-Phase Pipeline:**
818
- 1. Entity Analysis - Analyzes database schema and relationships
819
- 2. Entity Grouping - Creates logical groups of related entities
820
- 3. Business Question Generation - Uses AI to generate domain questions
821
- 4. Vector Similarity Search - Finds similar examples for few-shot learning
822
- 5. SQL Generation - Creates Nunjucks SQL templates with AI
823
- 6. Query Testing - Executes and validates queries
824
- 7. Error Fixing - Automatically fixes SQL errors using AI
825
- 8. Query Evaluation - Assesses query quality
826
- 9. Query Refinement - Iteratively improves queries
827
- 10. Testing & Validation - Comprehensive validation workflow
828
- 11. Metadata Export - Exports to MJ metadata or database
829
-
830
- **AI-Powered Features:**
831
- - Generates realistic business questions for your domain
832
- - Creates SQL queries with proper Nunjucks templating
833
- - Automatically tests and fixes SQL errors
834
- - Refines queries based on evaluation feedback
835
- - Uses few-shot learning with golden query examples
836
-
837
- **Integration:**
838
- - Outputs to MemberJunction metadata format
839
- - Compatible with `mj sync push` for database synchronization
840
- - Supports both metadata files and direct database writes
841
- - Uses MJ's Query entity with automatic field/parameter extraction
842
-
843
- ---
844
-
845
- ### Utility Commands
846
-
847
- #### `mj help`
848
-
849
- Display help information for any command.
850
-
851
- ```bash
852
- mj help [COMMAND]
229
+ mj querygen validate
853
230
  ```
854
231
 
855
- #### `mj version`
232
+ ### mj bump
856
233
 
857
- Display the CLI version and additional system information.
234
+ Version management for packages.
858
235
 
859
236
  ```bash
860
- mj version [--verbose] [--json]
237
+ mj bump
861
238
  ```
862
239
 
863
- ## Environment Variables
864
-
865
- The CLI respects the following environment variables:
866
-
867
- - Standard Node.js environment variables
868
- - Database connection variables set in `.env` files
869
- - Authentication provider settings (MSAL, Auth0)
870
-
871
- ## Integration with MemberJunction Packages
872
-
873
- The CLI integrates seamlessly with other MemberJunction packages:
874
-
875
- - **[@memberjunction/codegen-lib](../CodeGenLib)**: Powers the code generation functionality
876
- - **[@memberjunction/metadata-sync](../MetadataSync)**: Provides metadata synchronization capabilities ([README](../MetadataSync/README.md))
877
- - **[@memberjunction/query-gen](../QueryGen)**: AI-powered SQL query template generation ([README](../QueryGen/README.md))
878
- - **[@memberjunction/ai-cli](../AI/AICLI)**: Enables AI agent and action execution ([README](../AI/AICLI/README.md))
879
- - **[@memberjunction/testing-cli](../TestingFramework/CLI)**: Testing framework for database-driven tests ([README](../TestingFramework/CLI/README.md))
880
- - **[@memberjunction/db-auto-doc](../DBAutoDoc)**: AI-powered database documentation generator ([README](../DBAutoDoc/README.md))
881
- - **Generated Entities**: Automatically linked during installation
882
- - **MJAPI**: Configured and linked during installation
883
- - **MJExplorer**: UI configuration handled during installation
884
-
885
- ## Hooks
886
-
887
- The CLI implements the following hooks:
888
-
889
- - **prerun**: Displays the MemberJunction ASCII banner and version information
890
-
891
- ## Development
240
+ ### mj clean
892
241
 
893
- ### Building from Source
242
+ Clean build artifacts.
894
243
 
895
244
  ```bash
896
- npm run build
245
+ mj clean
897
246
  ```
898
247
 
899
- ### Scripts
900
-
901
- - `build`: Compile TypeScript to JavaScript
902
- - `prepack`: Build and generate oclif manifest
903
- - `postpack`: Clean up generated files
904
-
905
- ## Technical Details
906
-
907
- - Built with [oclif](https://oclif.io/) framework
908
- - Uses TypeScript for type safety
909
- - Implements Flyway for database migrations
910
- - Supports both global and project-specific configurations
911
- - Includes comprehensive error handling and validation
912
-
913
- ## Troubleshooting
914
-
915
- ### Common Issues
916
-
917
- 1. **Node Version Error**: Ensure you're using Node.js 20 or higher
918
- 2. **Database Connection**: Verify your database credentials and network access
919
- 3. **Disk Space**: The installation requires at least 2GB of free space
920
- 4. **Configuration Not Found**: Check that your config file is in a supported location
921
-
922
- ### Debug Mode
923
-
924
- Run any command with the `--verbose` flag for detailed logging:
248
+ ## Hooks
925
249
 
926
- ```bash
927
- mj install --verbose
928
- mj codegen --verbose
929
- mj ai agents run -a "My Agent" -p "My prompt" --verbose
930
- mj test run <test-id> --verbose
931
- mj dbdoc analyze --verbose
932
- ```
250
+ | Hook | Timing | Purpose |
251
+ |------|--------|---------|
252
+ | `init` | Before any command | Loads configuration, initializes environment |
253
+ | `prerun` | Before command execution | Validates configuration, connects to database |
254
+
255
+ ## Plugin System
256
+
257
+ The CLI includes these oclif plugins:
258
+
259
+ - `@oclif/plugin-help` -- Auto-generated help text
260
+ - `@oclif/plugin-version` -- Version display
261
+ - `@oclif/plugin-warn-if-update-available` -- Update notifications (checks daily)
262
+
263
+ ## Dependencies
264
+
265
+ | Package | Purpose |
266
+ |---------|---------|
267
+ | `@memberjunction/codegen-lib` | Code generation engine |
268
+ | `@memberjunction/metadata-sync` | Metadata synchronization |
269
+ | `@memberjunction/testing-cli` | Testing framework CLI |
270
+ | `@memberjunction/db-auto-doc` | Database documentation |
271
+ | `@memberjunction/query-gen` | Query generation |
272
+ | `@memberjunction/ai-cli` | AI operations |
273
+ | `@memberjunction/config` | Configuration management |
274
+ | `@memberjunction/server-bootstrap-lite` | Lightweight server initialization |
275
+ | `@memberjunction/sqlserver-dataprovider` | Database connectivity |
276
+ | `@oclif/core` | CLI framework |
277
+ | `cosmiconfig` | Configuration file loading |
278
+ | `node-flyway` | Database migration execution |
279
+ | `simple-git` | Git operations |
280
+ | `figlet` | ASCII art for banners |
933
281
 
934
282
  ## License
935
283
 
936
- ISC License - see the [LICENSE](https://github.com/MemberJunction/MJ/blob/main/LICENSE) file for details.
937
-
938
- ## Repository
939
-
940
- [https://github.com/MemberJunction/MJ](https://github.com/MemberJunction/MJ)
941
-
942
- ## Support
943
-
944
- For issues and feature requests, please visit the [GitHub Issues](https://github.com/MemberJunction/MJ/issues) page.
284
+ ISC