monarch-code-graph 0.3.4

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.
Files changed (53) hide show
  1. package/README.md +485 -0
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +100 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/analyze.d.ts +8 -0
  7. package/dist/commands/analyze.d.ts.map +1 -0
  8. package/dist/commands/analyze.js +76 -0
  9. package/dist/commands/analyze.js.map +1 -0
  10. package/dist/commands/diff.d.ts +8 -0
  11. package/dist/commands/diff.d.ts.map +1 -0
  12. package/dist/commands/diff.js +203 -0
  13. package/dist/commands/diff.js.map +1 -0
  14. package/dist/commands/graph.d.ts +12 -0
  15. package/dist/commands/graph.d.ts.map +1 -0
  16. package/dist/commands/graph.js +72 -0
  17. package/dist/commands/graph.js.map +1 -0
  18. package/dist/commands/help.d.ts +2 -0
  19. package/dist/commands/help.d.ts.map +1 -0
  20. package/dist/commands/help.js +234 -0
  21. package/dist/commands/help.js.map +1 -0
  22. package/dist/commands/init.d.ts +6 -0
  23. package/dist/commands/init.d.ts.map +1 -0
  24. package/dist/commands/init.js +37 -0
  25. package/dist/commands/init.js.map +1 -0
  26. package/dist/commands/list.d.ts +7 -0
  27. package/dist/commands/list.d.ts.map +1 -0
  28. package/dist/commands/list.js +148 -0
  29. package/dist/commands/list.js.map +1 -0
  30. package/dist/commands/run.d.ts +10 -0
  31. package/dist/commands/run.d.ts.map +1 -0
  32. package/dist/commands/run.js +388 -0
  33. package/dist/commands/run.js.map +1 -0
  34. package/dist/commands/serve.d.ts +8 -0
  35. package/dist/commands/serve.d.ts.map +1 -0
  36. package/dist/commands/serve.js +137 -0
  37. package/dist/commands/serve.js.map +1 -0
  38. package/dist/index.d.ts +6 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +7 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/queries/calls.ql +53 -0
  43. package/dist/queries/dataflow.ql +62 -0
  44. package/dist/queries/functions.ql +52 -0
  45. package/dist/utils/ascii-graph.d.ts +21 -0
  46. package/dist/utils/ascii-graph.d.ts.map +1 -0
  47. package/dist/utils/ascii-graph.js +431 -0
  48. package/dist/utils/ascii-graph.js.map +1 -0
  49. package/dist/utils/output.d.ts +12 -0
  50. package/dist/utils/output.d.ts.map +1 -0
  51. package/dist/utils/output.js +24 -0
  52. package/dist/utils/output.js.map +1 -0
  53. package/package.json +55 -0
package/README.md ADDED
@@ -0,0 +1,485 @@
1
+ <p align="center">
2
+ <img src="../../logo.png" alt="Monarch Logo" width="150" />
3
+ </p>
4
+
5
+ <h1 align="center">Monarch CLI</h1>
6
+
7
+ <p align="center">
8
+ Command-line interface for Monarch - static codebase flow mapping and visualization.
9
+ </p>
10
+
11
+ ## Installation
12
+
13
+ ### Global Installation (Recommended)
14
+
15
+ Install globally to use `monarch` as a command anywhere:
16
+
17
+ ```bash
18
+ # Using npm
19
+ npm install -g monarch-code-graph
20
+
21
+ # Using pnpm
22
+ pnpm add -g monarch-code-graph
23
+
24
+ # Using yarn
25
+ yarn global add monarch-code-graph
26
+ ```
27
+
28
+ After installation, the `monarch` command will be available globally:
29
+
30
+ ```bash
31
+ monarch --version
32
+ monarch --help
33
+ ```
34
+
35
+ ### Local Installation
36
+
37
+ Install as a dev dependency in your project:
38
+
39
+ ```bash
40
+ npm install --save-dev monarch-code-graph
41
+ ```
42
+
43
+ Then run via npx or package.json scripts:
44
+
45
+ ```bash
46
+ npx monarch analyze ./src
47
+ ```
48
+
49
+ ### From Source
50
+
51
+ If you're developing Monarch or want the latest version:
52
+
53
+ ```bash
54
+ # Clone the repository
55
+ git clone https://github.com/your-username/monarch.git
56
+ cd monarch
57
+
58
+ # Install dependencies
59
+ pnpm install
60
+
61
+ # Build all packages
62
+ pnpm build
63
+
64
+ # Link CLI globally
65
+ cd packages/cli
66
+ pnpm link --global
67
+ ```
68
+
69
+ ## Commands
70
+
71
+ ### `monarch run` (Recommended)
72
+
73
+ **All-in-one command** that analyzes your codebase, detects changes, and starts the visualization server. This is the recommended way to use Monarch during development.
74
+
75
+ ```bash
76
+ monarch run [path] [options]
77
+ ```
78
+
79
+ **Alias:** `monarch r`
80
+
81
+ **What it does:**
82
+ 1. Checks if a graph artifact already exists
83
+ 2. If exists, analyzes the codebase and compares for changes
84
+ 3. If no changes detected, skips regeneration (fast!)
85
+ 4. If changes detected, generates a new artifact
86
+ 5. Starts the visualization server
87
+ 6. Opens the browser (with `--open` flag)
88
+
89
+ **Arguments:**
90
+ | Argument | Description | Default |
91
+ |----------|-------------|---------|
92
+ | `path` | Path to the codebase to analyze | `.` (current directory) |
93
+
94
+ **Options:**
95
+ | Option | Description | Default |
96
+ |--------|-------------|---------|
97
+ | `-o, --output <path>` | Output artifact file path | `monarch-graph.json` |
98
+ | `-e, --exporter <name>` | Exporter to use (`mock`, `codeql-ts`) | `mock` |
99
+ | `-p, --port <number>` | Port for visualization server | `3000` |
100
+ | `--open` | Open browser automatically | `false` |
101
+ | `-f, --force` | Force regeneration even if no changes | `false` |
102
+
103
+ **Examples:**
104
+ ```bash
105
+ # Quick start - analyze and visualize
106
+ monarch run ./src --open
107
+
108
+ # Run on custom port
109
+ monarch run ./src -p 8080 --open
110
+
111
+ # Force regeneration
112
+ monarch run ./src --force
113
+
114
+ # With custom output file
115
+ monarch r ./src -o my-graph.json
116
+ ```
117
+
118
+ ---
119
+
120
+ ### `monarch init`
121
+
122
+ Initialize a new Monarch project in the current directory.
123
+
124
+ ```bash
125
+ monarch init [options]
126
+ ```
127
+
128
+ **Options:**
129
+ | Option | Description |
130
+ |--------|-------------|
131
+ | `-f, --force` | Overwrite existing configuration |
132
+
133
+ **Example:**
134
+ ```bash
135
+ # Create monarch.json configuration file
136
+ monarch init
137
+
138
+ # Overwrite existing config
139
+ monarch init --force
140
+ ```
141
+
142
+ This creates a `monarch.json` configuration file and suggests `.gitignore` entries.
143
+
144
+ ---
145
+
146
+ ### `monarch analyze`
147
+
148
+ Analyze a codebase and generate a flow artifact.
149
+
150
+ ```bash
151
+ monarch analyze [path] [options]
152
+ ```
153
+
154
+ **Alias:** `monarch a`
155
+
156
+ **Arguments:**
157
+ | Argument | Description | Default |
158
+ |----------|-------------|---------|
159
+ | `path` | Path to the codebase to analyze | `.` (current directory) |
160
+
161
+ **Options:**
162
+ | Option | Description | Default |
163
+ |--------|-------------|---------|
164
+ | `-o, --output <path>` | Output artifact file path | `monarch-graph.json` |
165
+ | `-e, --exporter <name>` | Exporter to use (`mock`, `codeql-ts`) | `mock` |
166
+ | `-w, --watch` | Watch for changes and re-analyze | `false` |
167
+
168
+ **Examples:**
169
+ ```bash
170
+ # Analyze current directory
171
+ monarch analyze
172
+
173
+ # Analyze a specific path
174
+ monarch analyze ./src
175
+
176
+ # Specify output file
177
+ monarch analyze ./src -o my-graph.json
178
+
179
+ # Use CodeQL exporter (requires CodeQL CLI)
180
+ monarch analyze ./src --exporter codeql-ts
181
+
182
+ # Short alias
183
+ monarch a ./src -o graph.json
184
+ ```
185
+
186
+ **Exporters:**
187
+
188
+ | Exporter | Description | Requirements |
189
+ |----------|-------------|--------------|
190
+ | `mock` | Fast regex-based TypeScript analysis | None |
191
+ | `codeql-ts` | Production-grade CodeQL analysis | [CodeQL CLI](https://github.com/github/codeql-cli-binaries) |
192
+
193
+ ---
194
+
195
+ ### `monarch diff`
196
+
197
+ Compare two graph artifacts and show changes.
198
+
199
+ ```bash
200
+ monarch diff <baseline> <current> [options]
201
+ ```
202
+
203
+ **Alias:** `monarch d`
204
+
205
+ **Arguments:**
206
+ | Argument | Description |
207
+ |----------|-------------|
208
+ | `baseline` | Path to the baseline artifact |
209
+ | `current` | Path to the current artifact |
210
+
211
+ **Options:**
212
+ | Option | Description | Default |
213
+ |--------|-------------|---------|
214
+ | `-f, --format <type>` | Output format (`text`, `json`, `markdown`) | `text` |
215
+ | `--exit-on-changes` | Exit with code 1 if changes detected | `false` |
216
+ | `--only <type>` | Show only specific changes (`functions`, `modules`, `edges`) | - |
217
+
218
+ **Examples:**
219
+ ```bash
220
+ # Compare two artifacts (text output)
221
+ monarch diff baseline.json current.json
222
+
223
+ # JSON output for programmatic use
224
+ monarch diff baseline.json current.json --format json
225
+
226
+ # Markdown output for reports
227
+ monarch diff baseline.json current.json --format markdown
228
+
229
+ # CI mode - fail if changes detected
230
+ monarch diff baseline.json current.json --exit-on-changes
231
+
232
+ # Show only function changes
233
+ monarch diff baseline.json current.json --only functions
234
+ ```
235
+
236
+ **Exit Codes:**
237
+ | Code | Meaning |
238
+ |------|---------|
239
+ | `0` | No changes detected (or `--exit-on-changes` not set) |
240
+ | `1` | Changes detected (with `--exit-on-changes`) or error |
241
+
242
+ ---
243
+
244
+ ### `monarch serve`
245
+
246
+ Start the visualization UI server.
247
+
248
+ ```bash
249
+ monarch serve [options]
250
+ ```
251
+
252
+ **Alias:** `monarch s`
253
+
254
+ **Options:**
255
+ | Option | Description | Default |
256
+ |--------|-------------|---------|
257
+ | `-p, --port <number>` | Port to serve on | `3000` |
258
+ | `-a, --artifact <path>` | Artifact file path | `monarch-graph.json` |
259
+ | `--open` | Open browser automatically | `false` |
260
+
261
+ **Examples:**
262
+ ```bash
263
+ # Start server with defaults
264
+ monarch serve
265
+
266
+ # Custom port
267
+ monarch serve --port 8080
268
+
269
+ # Specify artifact and open browser
270
+ monarch serve --artifact my-graph.json --open
271
+
272
+ # Short alias
273
+ monarch s -p 4000
274
+ ```
275
+
276
+ ---
277
+
278
+ ### `monarch list`
279
+
280
+ List contents of a graph artifact.
281
+
282
+ ```bash
283
+ monarch list [artifact] [options]
284
+ ```
285
+
286
+ **Alias:** `monarch ls`
287
+
288
+ **Arguments:**
289
+ | Argument | Description | Default |
290
+ |----------|-------------|---------|
291
+ | `artifact` | Path to artifact file | `monarch-graph.json` |
292
+
293
+ **Options:**
294
+ | Option | Description | Default |
295
+ |--------|-------------|---------|
296
+ | `-t, --type <type>` | Filter by type (`functions`, `modules`, `components`, `edges`) | - |
297
+ | `--json` | Output as JSON | `false` |
298
+
299
+ **Examples:**
300
+ ```bash
301
+ # List all contents
302
+ monarch list
303
+
304
+ # List specific artifact
305
+ monarch list my-graph.json
306
+
307
+ # Show only functions
308
+ monarch list --type functions
309
+
310
+ # JSON output
311
+ monarch list --json
312
+
313
+ # Show only modules as JSON
314
+ monarch list --type modules --json
315
+
316
+ # Short alias
317
+ monarch ls my-graph.json -t edges
318
+ ```
319
+
320
+ ## Configuration File
321
+
322
+ Create a `monarch.json` file in your project root:
323
+
324
+ ```json
325
+ {
326
+ "exporter": "mock",
327
+ "output": "monarch-graph.json",
328
+ "include": [
329
+ "src/**/*.ts",
330
+ "src/**/*.tsx"
331
+ ],
332
+ "exclude": [
333
+ "**/*.test.ts",
334
+ "**/*.spec.ts",
335
+ "**/node_modules/**"
336
+ ]
337
+ }
338
+ ```
339
+
340
+ ## CI/CD Integration
341
+
342
+ ### GitHub Actions
343
+
344
+ Add to your workflow:
345
+
346
+ ```yaml
347
+ name: CodeFlow Analysis
348
+
349
+ on: [push, pull_request]
350
+
351
+ jobs:
352
+ analyze:
353
+ runs-on: ubuntu-latest
354
+ steps:
355
+ - uses: actions/checkout@v4
356
+
357
+ - uses: pnpm/action-setup@v4
358
+ with:
359
+ version: 9
360
+
361
+ - uses: actions/setup-node@v4
362
+ with:
363
+ node-version: 20
364
+ cache: 'pnpm'
365
+
366
+ - run: pnpm install
367
+
368
+ - name: Generate artifact
369
+ run: npx monarch analyze ./src -o artifact.json
370
+
371
+ - name: Upload artifact
372
+ uses: actions/upload-artifact@v4
373
+ with:
374
+ name: monarch-artifact
375
+ path: artifact.json
376
+ ```
377
+
378
+ ### PR Diff Workflow
379
+
380
+ ```yaml
381
+ - name: Generate current
382
+ run: npx monarch analyze ./src -o current.json
383
+
384
+ # ... checkout base branch and generate baseline ...
385
+
386
+ - name: Compare
387
+ run: npx monarch diff baseline.json current.json --format markdown >> $GITHUB_STEP_SUMMARY
388
+ ```
389
+
390
+ ## Programmatic Usage
391
+
392
+ The CLI can also be used programmatically:
393
+
394
+ ```typescript
395
+ import { analyzeCommand, diffCommand } from 'monarch-cli';
396
+
397
+ // Analyze
398
+ await analyzeCommand('./src', {
399
+ output: 'graph.json',
400
+ exporter: 'mock',
401
+ watch: false,
402
+ });
403
+
404
+ // Diff
405
+ await diffCommand('baseline.json', 'current.json', {
406
+ format: 'json',
407
+ exitOnChanges: false,
408
+ });
409
+ ```
410
+
411
+ ## Building from Source
412
+
413
+ ```bash
414
+ # Clone repository
415
+ git clone https://github.com/your-username/monarch.git
416
+ cd monarch
417
+
418
+ # Install dependencies
419
+ pnpm install
420
+
421
+ # Build all packages (required - CLI depends on other packages)
422
+ pnpm build
423
+
424
+ # Run CLI directly
425
+ node packages/cli/dist/cli.js --help
426
+
427
+ # Or link globally
428
+ cd packages/cli
429
+ pnpm link --global
430
+ monarch --help
431
+ ```
432
+
433
+ ## Development
434
+
435
+ ```bash
436
+ # Run tests
437
+ pnpm --filter monarch-cli test
438
+
439
+ # Watch mode
440
+ pnpm --filter monarch-cli test:watch
441
+
442
+ # Type check
443
+ pnpm --filter monarch-cli typecheck
444
+
445
+ # Build only CLI
446
+ pnpm --filter monarch-cli build
447
+ ```
448
+
449
+ ## Troubleshooting
450
+
451
+ ### "Command not found: monarch"
452
+
453
+ Ensure global npm/pnpm binaries are in your PATH:
454
+
455
+ ```bash
456
+ # npm
457
+ export PATH="$PATH:$(npm config get prefix)/bin"
458
+
459
+ # pnpm
460
+ export PATH="$PATH:$(pnpm config get prefix)/bin"
461
+ ```
462
+
463
+ ### CodeQL Exporter Fails
464
+
465
+ 1. Verify CodeQL CLI is installed:
466
+ ```bash
467
+ codeql --version
468
+ ```
469
+
470
+ 2. If not installed, download from [CodeQL CLI Binaries](https://github.com/github/codeql-cli-binaries)
471
+
472
+ 3. Ensure the target project has JavaScript/TypeScript files
473
+
474
+ ### Artifact File Not Found
475
+
476
+ The default artifact path is `monarch-graph.json` in the current directory. Specify the path explicitly:
477
+
478
+ ```bash
479
+ monarch list ./path/to/artifact.json
480
+ monarch serve --artifact ./path/to/artifact.json
481
+ ```
482
+
483
+ ## License
484
+
485
+ Proprietary License - All rights reserved. See [LICENSE](../../LICENSE) for details.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { analyzeCommand } from './commands/analyze.js';
4
+ import { diffCommand } from './commands/diff.js';
5
+ import { serveCommand } from './commands/serve.js';
6
+ import { initCommand } from './commands/init.js';
7
+ import { listCommand } from './commands/list.js';
8
+ import { helpCommand } from './commands/help.js';
9
+ import { runCommand } from './commands/run.js';
10
+ import { graphCommand } from './commands/graph.js';
11
+ const program = new Command();
12
+ program
13
+ .name('monarch')
14
+ .description('Monarch - Static codebase flow mapping and visualization')
15
+ .version('0.1.0')
16
+ .addHelpCommand(false);
17
+ // Initialize a new Monarch project
18
+ program
19
+ .command('init')
20
+ .description('Initialize a new Monarch project in the current directory')
21
+ .option('-f, --force', 'Overwrite existing configuration', false)
22
+ .action(initCommand);
23
+ // Analyze a codebase and generate flow artifact
24
+ program
25
+ .command('analyze')
26
+ .alias('a')
27
+ .description('Analyze a codebase and generate flow artifact')
28
+ .argument('[path]', 'Path to the codebase', '.')
29
+ .option('-o, --output <path>', 'Output artifact path', 'monarch-graph.json')
30
+ .option('-e, --exporter <name>', 'Exporter to use (mock, codeql-ts)', 'mock')
31
+ .option('-w, --watch', 'Watch for changes and re-analyze', false)
32
+ .action(analyzeCommand);
33
+ // Compare two artifacts
34
+ program
35
+ .command('diff')
36
+ .alias('d')
37
+ .description('Compare two graph artifacts and show changes')
38
+ .argument('<baseline>', 'Path to baseline artifact')
39
+ .argument('<current>', 'Path to current artifact')
40
+ .option('-f, --format <type>', 'Output format (text, json, markdown)', 'text')
41
+ .option('--exit-on-changes', 'Exit with code 1 if changes detected', false)
42
+ .option('--only <type>', 'Show only specific changes (functions, modules, edges)')
43
+ .action(diffCommand);
44
+ // Start visualization server
45
+ program
46
+ .command('serve')
47
+ .alias('s')
48
+ .description('Start the visualization UI server')
49
+ .option('-p, --port <number>', 'Port to serve on', '3000')
50
+ .option('-a, --artifact <path>', 'Artifact file path', 'monarch-graph.json')
51
+ .option('--open', 'Open browser automatically', false)
52
+ .action(serveCommand);
53
+ // List contents of an artifact
54
+ program
55
+ .command('list')
56
+ .alias('ls')
57
+ .description('List contents of a graph artifact')
58
+ .argument('[artifact]', 'Path to artifact file', 'monarch-graph.json')
59
+ .option('-t, --type <type>', 'Filter by type (functions, modules, components, edges)')
60
+ .option('--json', 'Output as JSON', false)
61
+ .action(listCommand);
62
+ // Run: analyze, detect changes, and start server (all-in-one)
63
+ program
64
+ .command('run')
65
+ .alias('r')
66
+ .description('Analyze codebase, detect changes, and start visualization server')
67
+ .argument('[path]', 'Path to the codebase', '.')
68
+ .option('-o, --output <path>', 'Output artifact path', 'monarch-graph.json')
69
+ .option('-e, --exporter <name>', 'Exporter to use (mock, codeql-ts)', 'mock')
70
+ .option('-p, --port <number>', 'Port for visualization server', '3000')
71
+ .option('--open', 'Open browser automatically', false)
72
+ .option('-f, --force', 'Force regeneration even if no changes', false)
73
+ .action(runCommand);
74
+ // Graph: render ASCII graph in terminal
75
+ program
76
+ .command('graph')
77
+ .alias('g')
78
+ .description('Render ASCII graph visualization in terminal')
79
+ .argument('[artifact]', 'Path to artifact file', 'monarch-graph.json')
80
+ .option('-l, --level <level>', 'View level (components, modules, functions)', 'modules')
81
+ .option('-x, --expand <name>', 'Expand a specific component or module by name')
82
+ .option('--expand-type <type>', 'Type of item to expand (component, module)')
83
+ .option('--list', 'List expandable components and modules', false)
84
+ .option('--no-color', 'Disable colored output')
85
+ .option('-w, --width <cols>', 'Max output width in columns')
86
+ .action(graphCommand);
87
+ // Comprehensive help command
88
+ program
89
+ .command('help')
90
+ .description('Show detailed help for Monarch or a specific command')
91
+ .argument('[command]', 'Command to get help for')
92
+ .action(helpCommand);
93
+ // Show custom help when no command is provided
94
+ if (process.argv.length === 2) {
95
+ helpCommand();
96
+ process.exit(0);
97
+ }
98
+ // Parse and execute
99
+ program.parse();
100
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,SAAS,CAAC;KACf,WAAW,CAAC,0DAA0D,CAAC;KACvE,OAAO,CAAC,OAAO,CAAC;KAChB,cAAc,CAAC,KAAK,CAAC,CAAC;AAEzB,mCAAmC;AACnC,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,2DAA2D,CAAC;KACxE,MAAM,CAAC,aAAa,EAAE,kCAAkC,EAAE,KAAK,CAAC;KAChE,MAAM,CAAC,WAAW,CAAC,CAAC;AAEvB,gDAAgD;AAChD,OAAO;KACJ,OAAO,CAA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A6B;AAC7B,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,sDAAsD,CAAC;KACnE,QAAQ,CAAC,WAAW,EAAE,yBAAyB,CAAC;KAChD,MAAM,CAAC,WAAW,CAAC,CAAC;AAEvB,+CAA+C;AAC/C,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC9B,WAAW,EAAE,CAAC;IACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,oBAAoB;AACpB,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ interface AnalyzeOptions {
2
+ output: string;
3
+ exporter: string;
4
+ watch: boolean;
5
+ }
6
+ export declare function analyzeCommand(targetPath: string, options: AnalyzeOptions): Promise<void>;
7
+ export {};
8
+ //# sourceMappingURL=analyze.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/commands/analyze.ts"],"names":[],"mappings":"AAOA,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC,CA6Ef"}
@@ -0,0 +1,76 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import ora from 'ora';
4
+ import { MockExporter, applyElkLayout } from '@codeflow/analyzer';
5
+ import { log, formatPath, formatNumber } from '../utils/output.js';
6
+ export async function analyzeCommand(targetPath, options) {
7
+ const absolutePath = path.resolve(targetPath);
8
+ if (!fs.existsSync(absolutePath)) {
9
+ log.error(`Path does not exist: ${formatPath(absolutePath)}`);
10
+ process.exit(1);
11
+ }
12
+ log.title('Monarch Analysis');
13
+ log.info(`Target: ${formatPath(absolutePath)}`);
14
+ log.info(`Exporter: ${options.exporter}`);
15
+ log.info(`Output: ${formatPath(options.output)}`);
16
+ const spinner = ora('Analyzing codebase...').start();
17
+ try {
18
+ let artifact;
19
+ if (options.exporter === 'mock') {
20
+ const exporter = new MockExporter(absolutePath);
21
+ await exporter.prepare();
22
+ spinner.text = 'Scanning files...';
23
+ await exporter.analyze();
24
+ spinner.text = 'Generating artifact...';
25
+ artifact = await exporter.export();
26
+ await exporter.cleanup();
27
+ }
28
+ else if (options.exporter === 'codeql-ts') {
29
+ spinner.text = 'Creating CodeQL database...';
30
+ // Dynamic import to avoid loading CodeQL dependencies if not needed
31
+ const { CodeQLExporter } = await import('@codeflow/analyzer');
32
+ const exporter = new CodeQLExporter(absolutePath);
33
+ await exporter.prepare();
34
+ spinner.text = 'Running CodeQL queries...';
35
+ await exporter.analyze();
36
+ spinner.text = 'Generating artifact...';
37
+ artifact = await exporter.export();
38
+ await exporter.cleanup();
39
+ }
40
+ else {
41
+ spinner.fail(`Unknown exporter: ${options.exporter}`);
42
+ process.exit(1);
43
+ }
44
+ // Apply layout
45
+ spinner.text = 'Computing layout...';
46
+ artifact = await applyElkLayout(artifact);
47
+ // Ensure output directory exists
48
+ const outputDir = path.dirname(path.resolve(options.output));
49
+ if (!fs.existsSync(outputDir)) {
50
+ fs.mkdirSync(outputDir, { recursive: true });
51
+ }
52
+ // Write artifact
53
+ const outputPath = path.resolve(options.output);
54
+ fs.writeFileSync(outputPath, JSON.stringify(artifact, null, 2));
55
+ spinner.succeed('Analysis complete!');
56
+ // Print summary
57
+ console.log('');
58
+ log.success(`Graph saved to ${formatPath(outputPath)}`);
59
+ console.log('');
60
+ log.info(`Functions: ${formatNumber(artifact.nodes.functions.length)}`);
61
+ log.info(`Modules: ${formatNumber(artifact.nodes.modules.length)}`);
62
+ log.info(`Components: ${formatNumber(artifact.nodes.components.length)}`);
63
+ log.info(`Call edges: ${formatNumber(artifact.edges.calls.length)}`);
64
+ log.info(`Dataflow: ${formatNumber(artifact.edges.dataflow.length)}`);
65
+ if (options.watch) {
66
+ log.info('\nWatching for changes... (press Ctrl+C to stop)');
67
+ // TODO: Implement file watching
68
+ }
69
+ }
70
+ catch (error) {
71
+ spinner.fail('Analysis failed');
72
+ log.error(String(error));
73
+ process.exit(1);
74
+ }
75
+ }
76
+ //# sourceMappingURL=analyze.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../src/commands/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAQnE,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,UAAkB,EAClB,OAAuB;IAEvB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAE9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,GAAG,CAAC,KAAK,CAAC,wBAAwB,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,GAAG,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC9B,GAAG,CAAC,IAAI,CAAC,WAAW,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAChD,GAAG,CAAC,IAAI,CAAC,aAAa,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1C,GAAG,CAAC,IAAI,CAAC,WAAW,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,GAAG,CAAC,uBAAuB,CAAC,CAAC,KAAK,E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