spec-gen-cli 1.1.0 → 1.2.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 +163 -77
- package/dist/api/analyze.d.ts.map +1 -1
- package/dist/api/analyze.js +56 -27
- package/dist/api/analyze.js.map +1 -1
- package/dist/api/drift.d.ts.map +1 -1
- package/dist/api/drift.js +26 -20
- package/dist/api/drift.js.map +1 -1
- package/dist/api/generate.d.ts.map +1 -1
- package/dist/api/generate.js +19 -43
- package/dist/api/generate.js.map +1 -1
- package/dist/api/init.d.ts.map +1 -1
- package/dist/api/init.js +6 -5
- package/dist/api/init.js.map +1 -1
- package/dist/api/run.d.ts.map +1 -1
- package/dist/api/run.js +67 -51
- package/dist/api/run.js.map +1 -1
- package/dist/api/specs.d.ts.map +1 -1
- package/dist/api/specs.js +5 -4
- package/dist/api/specs.js.map +1 -1
- package/dist/api/types.d.ts +7 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/verify.d.ts.map +1 -1
- package/dist/api/verify.js +31 -32
- package/dist/api/verify.js.map +1 -1
- package/dist/cli/commands/analyze.d.ts.map +1 -1
- package/dist/cli/commands/analyze.js +41 -62
- package/dist/cli/commands/analyze.js.map +1 -1
- package/dist/cli/commands/doctor.d.ts +9 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +273 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/drift.d.ts.map +1 -1
- package/dist/cli/commands/drift.js +18 -32
- package/dist/cli/commands/drift.js.map +1 -1
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +40 -101
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +17 -15
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +2 -1
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/run.d.ts +0 -15
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +61 -111
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/commands/verify.d.ts.map +1 -1
- package/dist/cli/commands/verify.js +18 -52
- package/dist/cli/commands/verify.js.map +1 -1
- package/dist/cli/commands/view.d.ts +4 -0
- package/dist/cli/commands/view.d.ts.map +1 -1
- package/dist/cli/commands/view.js +29 -24
- package/dist/cli/commands/view.js.map +1 -1
- package/dist/cli/index.js +22 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/constants.d.ts +254 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +320 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/analyzer/artifact-generator.d.ts +8 -0
- package/dist/core/analyzer/artifact-generator.d.ts.map +1 -1
- package/dist/core/analyzer/artifact-generator.js +59 -11
- package/dist/core/analyzer/artifact-generator.js.map +1 -1
- package/dist/core/analyzer/call-graph.d.ts.map +1 -1
- package/dist/core/analyzer/call-graph.js +135 -1
- package/dist/core/analyzer/call-graph.js.map +1 -1
- package/dist/core/analyzer/dependency-graph.d.ts +32 -0
- package/dist/core/analyzer/dependency-graph.d.ts.map +1 -1
- package/dist/core/analyzer/dependency-graph.js +104 -10
- package/dist/core/analyzer/dependency-graph.js.map +1 -1
- package/dist/core/analyzer/duplicate-detector.d.ts.map +1 -1
- package/dist/core/analyzer/duplicate-detector.js +4 -0
- package/dist/core/analyzer/duplicate-detector.js.map +1 -1
- package/dist/core/analyzer/embedding-service.d.ts +6 -0
- package/dist/core/analyzer/embedding-service.d.ts.map +1 -1
- package/dist/core/analyzer/embedding-service.js +15 -1
- package/dist/core/analyzer/embedding-service.js.map +1 -1
- package/dist/core/analyzer/file-walker.d.ts.map +1 -1
- package/dist/core/analyzer/file-walker.js +4 -3
- package/dist/core/analyzer/file-walker.js.map +1 -1
- package/dist/core/analyzer/http-route-parser.d.ts +111 -0
- package/dist/core/analyzer/http-route-parser.d.ts.map +1 -0
- package/dist/core/analyzer/http-route-parser.js +466 -0
- package/dist/core/analyzer/http-route-parser.js.map +1 -0
- package/dist/core/analyzer/import-parser.d.ts.map +1 -1
- package/dist/core/analyzer/import-parser.js +19 -5
- package/dist/core/analyzer/import-parser.js.map +1 -1
- package/dist/core/analyzer/refactor-analyzer.d.ts.map +1 -1
- package/dist/core/analyzer/refactor-analyzer.js +8 -7
- package/dist/core/analyzer/refactor-analyzer.js.map +1 -1
- package/dist/core/analyzer/repository-mapper.d.ts.map +1 -1
- package/dist/core/analyzer/repository-mapper.js +12 -13
- package/dist/core/analyzer/repository-mapper.js.map +1 -1
- package/dist/core/analyzer/signature-extractor.d.ts +1 -1
- package/dist/core/analyzer/signature-extractor.d.ts.map +1 -1
- package/dist/core/analyzer/signature-extractor.js +69 -1
- package/dist/core/analyzer/signature-extractor.js.map +1 -1
- package/dist/core/analyzer/spec-vector-index.d.ts.map +1 -1
- package/dist/core/analyzer/spec-vector-index.js +4 -3
- package/dist/core/analyzer/spec-vector-index.js.map +1 -1
- package/dist/core/analyzer/vector-index.d.ts.map +1 -1
- package/dist/core/analyzer/vector-index.js +29 -1
- package/dist/core/analyzer/vector-index.js.map +1 -1
- package/dist/core/drift/drift-detector.d.ts.map +1 -1
- package/dist/core/drift/drift-detector.js +7 -6
- package/dist/core/drift/drift-detector.js.map +1 -1
- package/dist/core/drift/git-diff.d.ts.map +1 -1
- package/dist/core/drift/git-diff.js +28 -16
- package/dist/core/drift/git-diff.js.map +1 -1
- package/dist/core/generator/mapping-generator.d.ts.map +1 -1
- package/dist/core/generator/mapping-generator.js +11 -10
- package/dist/core/generator/mapping-generator.js.map +1 -1
- package/dist/core/generator/openspec-compat.d.ts.map +1 -1
- package/dist/core/generator/openspec-compat.js +3 -2
- package/dist/core/generator/openspec-compat.js.map +1 -1
- package/dist/core/generator/openspec-format-generator.js.map +1 -1
- package/dist/core/generator/openspec-writer.d.ts +0 -4
- package/dist/core/generator/openspec-writer.d.ts.map +1 -1
- package/dist/core/generator/openspec-writer.js +30 -41
- package/dist/core/generator/openspec-writer.js.map +1 -1
- package/dist/core/generator/spec-pipeline.d.ts.map +1 -1
- package/dist/core/generator/spec-pipeline.js +4 -4
- package/dist/core/generator/spec-pipeline.js.map +1 -1
- package/dist/core/generator/stages/stage1-survey.d.ts.map +1 -1
- package/dist/core/generator/stages/stage1-survey.js +5 -3
- package/dist/core/generator/stages/stage1-survey.js.map +1 -1
- package/dist/core/generator/stages/stage2-entities.d.ts.map +1 -1
- package/dist/core/generator/stages/stage2-entities.js +10 -9
- package/dist/core/generator/stages/stage2-entities.js.map +1 -1
- package/dist/core/generator/stages/stage3-services.d.ts.map +1 -1
- package/dist/core/generator/stages/stage3-services.js +9 -8
- package/dist/core/generator/stages/stage3-services.js.map +1 -1
- package/dist/core/generator/stages/stage4-api.d.ts.map +1 -1
- package/dist/core/generator/stages/stage4-api.js +10 -9
- package/dist/core/generator/stages/stage4-api.js.map +1 -1
- package/dist/core/generator/stages/stage5-architecture.d.ts.map +1 -1
- package/dist/core/generator/stages/stage5-architecture.js +5 -4
- package/dist/core/generator/stages/stage5-architecture.js.map +1 -1
- package/dist/core/generator/stages/stage6-adr.d.ts.map +1 -1
- package/dist/core/generator/stages/stage6-adr.js +7 -2
- package/dist/core/generator/stages/stage6-adr.js.map +1 -1
- package/dist/core/services/chat-agent.d.ts.map +1 -1
- package/dist/core/services/chat-agent.js +46 -15
- package/dist/core/services/chat-agent.js.map +1 -1
- package/dist/core/services/config-manager.d.ts.map +1 -1
- package/dist/core/services/config-manager.js +32 -26
- package/dist/core/services/config-manager.js.map +1 -1
- package/dist/core/services/gitignore-manager.d.ts.map +1 -1
- package/dist/core/services/gitignore-manager.js +2 -13
- package/dist/core/services/gitignore-manager.js.map +1 -1
- package/dist/core/services/llm-service.d.ts.map +1 -1
- package/dist/core/services/llm-service.js +33 -35
- package/dist/core/services/llm-service.js.map +1 -1
- package/dist/core/services/mcp-handlers/analysis.d.ts.map +1 -1
- package/dist/core/services/mcp-handlers/analysis.js +23 -14
- package/dist/core/services/mcp-handlers/analysis.js.map +1 -1
- package/dist/core/services/mcp-handlers/graph.d.ts.map +1 -1
- package/dist/core/services/mcp-handlers/graph.js +24 -23
- package/dist/core/services/mcp-handlers/graph.js.map +1 -1
- package/dist/core/services/mcp-handlers/semantic.d.ts +1 -1
- package/dist/core/services/mcp-handlers/semantic.d.ts.map +1 -1
- package/dist/core/services/mcp-handlers/semantic.js +17 -16
- package/dist/core/services/mcp-handlers/semantic.js.map +1 -1
- package/dist/core/services/mcp-handlers/utils.d.ts.map +1 -1
- package/dist/core/services/mcp-handlers/utils.js +4 -3
- package/dist/core/services/mcp-handlers/utils.js.map +1 -1
- package/dist/core/services/project-detector.d.ts.map +1 -1
- package/dist/core/services/project-detector.js +2 -13
- package/dist/core/services/project-detector.js.map +1 -1
- package/dist/core/verifier/verification-engine.d.ts +9 -3
- package/dist/core/verifier/verification-engine.d.ts.map +1 -1
- package/dist/core/verifier/verification-engine.js +25 -13
- package/dist/core/verifier/verification-engine.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/command-helpers.d.ts +38 -0
- package/dist/utils/command-helpers.d.ts.map +1 -0
- package/dist/utils/command-helpers.js +82 -0
- package/dist/utils/command-helpers.js.map +1 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +4 -3
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +14 -3
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/progress.d.ts +1 -1
- package/dist/utils/progress.d.ts.map +1 -1
- package/dist/utils/progress.js +15 -12
- package/dist/utils/progress.js.map +1 -1
- package/dist/utils/shutdown.d.ts.map +1 -1
- package/dist/utils/shutdown.js +4 -3
- package/dist/utils/shutdown.js.map +1 -1
- package/package.json +9 -5
- package/src/viewer/InteractiveGraphViewer.jsx +182 -139
- package/src/viewer/components/ArchitectureView.jsx +19 -19
- package/src/viewer/components/ChatPanel.jsx +40 -40
- package/src/viewer/components/ClusterGraph.jsx +34 -22
- package/src/viewer/components/FilterBar.jsx +26 -26
- package/src/viewer/components/FlatGraph.jsx +22 -15
- package/src/viewer/components/MicroComponents.jsx +14 -12
- package/src/viewer/utils/constants.js +17 -0
- package/src/viewer/utils/graph-helpers.js +7 -3
- package/src/viewer/utils/graph-helpers.test.ts +39 -0
- package/src/viewer/utils/themes.js +170 -0
package/README.md
CHANGED
|
@@ -22,6 +22,9 @@ spec-gen init # Detect project type, create config
|
|
|
22
22
|
spec-gen analyze # Static analysis (no API key needed)
|
|
23
23
|
spec-gen generate # Generate specs (requires API key)
|
|
24
24
|
spec-gen drift # Check for spec drift
|
|
25
|
+
|
|
26
|
+
# Troubleshoot setup issues
|
|
27
|
+
spec-gen doctor # Check environment and configuration
|
|
25
28
|
```
|
|
26
29
|
|
|
27
30
|
<details>
|
|
@@ -86,8 +89,10 @@ npm run dev
|
|
|
86
89
|
|
|
87
90
|
Scans your codebase using pure static analysis:
|
|
88
91
|
- Walks the directory tree, respects .gitignore, scores files by significance
|
|
89
|
-
- Parses imports and exports to build a dependency graph
|
|
90
|
-
-
|
|
92
|
+
- Parses imports and exports to build a dependency graph (TypeScript, JavaScript, Python, Go, Rust, Ruby, Java, C++)
|
|
93
|
+
- Detects HTTP cross-language edges: matches `fetch`/`axios`/`ky`/`got` calls in JS/TS files to FastAPI/Flask/Django route definitions in Python files, creating cross-language dependency edges with `exact`, `path`, or `fuzzy` confidence
|
|
94
|
+
- Resolves Python absolute imports (`from services.retriever import X`) to local files
|
|
95
|
+
- Clusters related files into structural business domains automatically
|
|
91
96
|
- Produces structured context that makes LLM generation more accurate
|
|
92
97
|
|
|
93
98
|
**2. Generate** (API key required)
|
|
@@ -143,6 +148,8 @@ graph TD
|
|
|
143
148
|
FW[File Walker] --> SS[Significance Scorer]
|
|
144
149
|
SS --> IP[Import Parser]
|
|
145
150
|
IP --> DG[Dependency Graph]
|
|
151
|
+
SS --> HR[HTTP Route Parser]
|
|
152
|
+
HR -->|cross-language edges| DG
|
|
146
153
|
DG --> RM[Repository Mapper]
|
|
147
154
|
RM --> AG[Artifact Generator]
|
|
148
155
|
end
|
|
@@ -412,6 +419,7 @@ Priority: CLI flags > environment variables > config file > provider defaults.
|
|
|
412
419
|
| `spec-gen run` | Full pipeline: init, analyze, generate | Yes |
|
|
413
420
|
| `spec-gen view` | Launch interactive graph & spec viewer in the browser | No |
|
|
414
421
|
| `spec-gen mcp` | Start MCP server (stdio, for Cline / Claude Code) | No |
|
|
422
|
+
| `spec-gen doctor` | Check environment and configuration for common issues | No |
|
|
415
423
|
|
|
416
424
|
### Global Options
|
|
417
425
|
|
|
@@ -440,6 +448,7 @@ spec-gen drift [options]
|
|
|
440
448
|
--json # JSON output
|
|
441
449
|
--fail-on <severity> # Exit non-zero threshold: error, warning, info
|
|
442
450
|
--max-files <n> # Max changed files to analyze (default: 100)
|
|
451
|
+
--verbose # Show detailed issue information
|
|
443
452
|
--install-hook # Install pre-commit hook
|
|
444
453
|
--uninstall-hook # Remove pre-commit hook
|
|
445
454
|
```
|
|
@@ -455,6 +464,23 @@ spec-gen generate [options]
|
|
|
455
464
|
--no-overwrite # Skip existing files
|
|
456
465
|
--adr # Also generate ADRs
|
|
457
466
|
--adr-only # Generate only ADRs
|
|
467
|
+
--reanalyze # Force fresh analysis even if recent exists
|
|
468
|
+
--analysis <path> # Path to existing analysis directory
|
|
469
|
+
--output-dir <path> # Override openspec output location
|
|
470
|
+
-y, --yes # Skip confirmation prompts
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
### Run Options
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
spec-gen run [options]
|
|
477
|
+
--force # Reinitialize even if config exists
|
|
478
|
+
--reanalyze # Force fresh analysis even if recent exists
|
|
479
|
+
--model <name> # LLM model to use for generation
|
|
480
|
+
--dry-run # Show what would be done without making changes
|
|
481
|
+
-y, --yes # Skip all confirmation prompts
|
|
482
|
+
--max-files <n> # Maximum files to analyze (default: 500)
|
|
483
|
+
--adr # Also generate Architecture Decision Records
|
|
458
484
|
```
|
|
459
485
|
|
|
460
486
|
### Analyze Options
|
|
@@ -467,6 +493,7 @@ spec-gen analyze [options]
|
|
|
467
493
|
--exclude <glob> # Additional exclude patterns
|
|
468
494
|
--force # Force re-analysis (bypass 1-hour cache)
|
|
469
495
|
--embed # Build semantic vector index after analysis (requires embedding config)
|
|
496
|
+
--reindex-specs # Re-index OpenSpec specs into the vector index without re-running full analysis
|
|
470
497
|
```
|
|
471
498
|
|
|
472
499
|
### Verify Options
|
|
@@ -477,52 +504,53 @@ spec-gen verify [options]
|
|
|
477
504
|
--threshold <0-1> # Minimum score to pass (default: 0.7)
|
|
478
505
|
--files <paths> # Specific files to verify
|
|
479
506
|
--domains <list> # Only verify specific domains
|
|
507
|
+
--verbose # Show detailed prediction vs actual comparison
|
|
480
508
|
--json # JSON output
|
|
481
509
|
```
|
|
482
510
|
|
|
511
|
+
### Doctor
|
|
512
|
+
|
|
513
|
+
`spec-gen doctor` runs a self-diagnostic and surfaces actionable fixes when something is misconfigured or missing:
|
|
514
|
+
|
|
515
|
+
```bash
|
|
516
|
+
spec-gen doctor # Run all checks
|
|
517
|
+
spec-gen doctor --json # JSON output for scripting
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
Checks performed:
|
|
521
|
+
|
|
522
|
+
| Check | What it looks for |
|
|
523
|
+
|-------|------------------|
|
|
524
|
+
| Node.js version | ≥ 20 required |
|
|
525
|
+
| Git repository | `.git` directory and `git` binary on PATH |
|
|
526
|
+
| spec-gen config | `.spec-gen/config.json` exists and is parseable |
|
|
527
|
+
| Analysis artifacts | `repo-structure.json` freshness (warns if >24h old) |
|
|
528
|
+
| OpenSpec directory | `openspec/specs/` exists |
|
|
529
|
+
| LLM provider | API key or `claude` CLI detected |
|
|
530
|
+
| Disk space | Warns < 500 MB, fails < 200 MB |
|
|
531
|
+
|
|
532
|
+
Run `spec-gen doctor` whenever setup instructions aren't working — it tells you exactly what to fix and how.
|
|
533
|
+
|
|
483
534
|
## MCP Server
|
|
484
535
|
|
|
485
536
|
`spec-gen mcp` starts spec-gen as a [Model Context Protocol](https://modelcontextprotocol.io/) server over stdio, exposing static analysis as tools that any MCP-compatible AI agent (Cline, Roo Code, Kilocode, Claude Code, Cursor...) can call directly -- no API key required.
|
|
486
537
|
|
|
487
538
|
### Setup
|
|
488
539
|
|
|
489
|
-
**Claude Code** -- add a `.mcp.json` at your project root
|
|
540
|
+
**Claude Code** -- add a `.mcp.json` at your project root:
|
|
490
541
|
|
|
491
542
|
```json
|
|
492
543
|
{
|
|
493
544
|
"mcpServers": {
|
|
494
545
|
"spec-gen": {
|
|
495
|
-
"command": "
|
|
496
|
-
"args": ["
|
|
546
|
+
"command": "spec-gen",
|
|
547
|
+
"args": ["mcp"]
|
|
497
548
|
}
|
|
498
549
|
}
|
|
499
550
|
}
|
|
500
551
|
```
|
|
501
552
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
### Quick Start
|
|
505
|
-
|
|
506
|
-
**1. Build spec-gen**
|
|
507
|
-
|
|
508
|
-
```bash
|
|
509
|
-
git clone https://github.com/clay-good/spec-gen
|
|
510
|
-
cd spec-gen && npm install && npm run build
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
**2. Generate specs once** (required for drift detection and naming alignment)
|
|
514
|
-
|
|
515
|
-
```bash
|
|
516
|
-
cd /path/to/your-project
|
|
517
|
-
spec-gen init # detect project type, create config
|
|
518
|
-
spec-gen generate # generate OpenSpec specs (requires LLM API key)
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
**3. Connect your editor**
|
|
522
|
-
|
|
523
|
-
#### Claude Code
|
|
524
|
-
|
|
525
|
-
The repo ships a `.mcp.json` -- edit the path and you are done:
|
|
553
|
+
or for local development:
|
|
526
554
|
|
|
527
555
|
```json
|
|
528
556
|
{
|
|
@@ -535,61 +563,54 @@ The repo ships a `.mcp.json` -- edit the path and you are done:
|
|
|
535
563
|
}
|
|
536
564
|
```
|
|
537
565
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
```
|
|
541
|
-
You: Analyse my codebase and tell me what needs refactoring most urgently
|
|
542
|
-
Claude: [analyze_codebase -> get_refactor_report -> analyze_impact on top result]
|
|
543
|
-
-> Project summary, top issues ranked by priority, risk score and recommended
|
|
544
|
-
strategy for the highest-impact function
|
|
545
|
-
|
|
546
|
-
You: Are there any duplicate functions I should consolidate?
|
|
547
|
-
Claude: [get_duplicate_report]
|
|
548
|
-
-> Clone groups sorted by impact (exact / structural / near), file paths, line ranges
|
|
549
|
-
|
|
550
|
-
You: Show me everything that calls parseConfig and draw a diagram
|
|
551
|
-
Claude: [get_subgraph with direction: "upstream", format: "mermaid"]
|
|
552
|
-
-> Mermaid flowchart of the upstream call chain
|
|
553
|
-
```
|
|
566
|
+
**Cline / Roo Code / Kilocode** -- add the same block under `mcpServers` in the MCP settings JSON of your editor.
|
|
554
567
|
|
|
555
|
-
|
|
568
|
+
### Cline / Roo Code / Kilocode
|
|
556
569
|
|
|
557
|
-
|
|
570
|
+
For editors with MCP support, after adding the `mcpServers` block to your settings, download the slash command workflows:
|
|
558
571
|
|
|
559
572
|
```bash
|
|
560
|
-
cd /path/to/your-project
|
|
561
573
|
mkdir -p .clinerules/workflows
|
|
562
|
-
|
|
574
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/examples/cline-workflows/spec-gen-analyze-codebase.md -o .clinerules/workflows/spec-gen-analyze-codebase.md
|
|
575
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/examples/cline-workflows/spec-gen-check-spec-drift.md -o .clinerules/workflows/spec-gen-check-spec-drift.md
|
|
576
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/examples/cline-workflows/spec-gen-plan-refactor.md -o .clinerules/workflows/spec-gen-plan-refactor.md
|
|
577
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/examples/cline-workflows/spec-gen-execute-refactor.md -o .clinerules/workflows/spec-gen-execute-refactor.md
|
|
578
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/examples/cline-workflows/spec-gen-implement-feature.md -o .clinerules/workflows/spec-gen-implement-feature.md
|
|
579
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/examples/cline-workflows/spec-gen-refactor-codebase.md -o .clinerules/workflows/spec-gen-refactor-codebase.md
|
|
563
580
|
```
|
|
564
581
|
|
|
565
|
-
|
|
582
|
+
Available commands:
|
|
566
583
|
|
|
567
|
-
| Command |
|
|
568
|
-
|
|
569
|
-
| `/spec-gen-analyze-codebase` |
|
|
570
|
-
| `/spec-gen-check-spec-drift` |
|
|
571
|
-
| `/spec-gen-plan-refactor` |
|
|
572
|
-
| `/spec-gen-execute-refactor` |
|
|
584
|
+
| Command | What it does |
|
|
585
|
+
|---------|-------------|
|
|
586
|
+
| `/spec-gen-analyze-codebase` | Runs `analyze_codebase`, summarises the results (project type, file count, top 3 refactor issues, detected domains), shows the call graph highlights, and suggests next steps. |
|
|
587
|
+
| `/spec-gen-check-spec-drift` | Runs `check_spec_drift`, presents issues by severity (gap / stale / uncovered / orphaned-spec), shows per-kind remediation commands, and optionally drills into affected file signatures. |
|
|
588
|
+
| `/spec-gen-plan-refactor` | Runs static analysis, picks the highest-priority target with coverage gate, assesses impact and call graph, then writes a detailed plan to `.spec-gen/refactor-plan.md`. No code changes. |
|
|
589
|
+
| `/spec-gen-execute-refactor` | Reads `.spec-gen/refactor-plan.md`, establishes a green baseline, and applies each planned change one at a time -- with diff verification and test run after every step. Optional final step covers dead-code detection and naming alignment (requires `spec-gen generate`). |
|
|
590
|
+
| `/spec-gen-implement-feature` | Plans and implements a new feature with full architectural context: architecture overview, OpenSpec requirements, insertion points, implementation, and drift check. |
|
|
591
|
+
| `/spec-gen-refactor-codebase` | Convenience redirect that runs `/spec-gen-plan-refactor` followed by `/spec-gen-execute-refactor`. |
|
|
573
592
|
|
|
574
|
-
|
|
593
|
+
All six commands ask which directory to use, call the MCP tools directly, and guide you through the results without leaving the editor. They work in any editor that supports the `.clinerules/workflows/` convention.
|
|
575
594
|
|
|
576
|
-
###
|
|
595
|
+
### Claude Skills
|
|
577
596
|
|
|
578
|
-
|
|
597
|
+
For Claude Code, copy the skill files to `.claude/skills/` in your project:
|
|
579
598
|
|
|
580
599
|
```bash
|
|
581
|
-
mkdir -p .
|
|
582
|
-
|
|
600
|
+
mkdir -p .claude/skills
|
|
601
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/skills/claude-spec-gen.md -o .claude/skills/claude-spec-gen.md
|
|
602
|
+
curl -sL https://raw.githubusercontent.com/clay-good/spec-gen/main/skills/openspec-skill.md -o .claude/skills/openspec-skill.md
|
|
583
603
|
```
|
|
584
604
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
| `/spec-gen-plan-refactor` | Runs static analysis, picks the highest-priority target with coverage gate, assesses impact and call graph, then writes a detailed plan to `.spec-gen/refactor-plan.md`. No code changes. |
|
|
590
|
-
| `/spec-gen-execute-refactor` | Reads `.spec-gen/refactor-plan.md`, establishes a green baseline, and applies each planned change one at a time -- with diff verification and test run after every step. Optional final step covers dead-code detection and naming alignment (requires `spec-gen generate`). |
|
|
605
|
+
**Spec-Gen Skill** (`claude-spec-gen.md`) — Code archaeology skill that guides Claude through:
|
|
606
|
+
- Project type detection and domain identification
|
|
607
|
+
- Entity extraction, service analysis, API extraction
|
|
608
|
+
- Architecture synthesis and OpenSpec spec generation
|
|
591
609
|
|
|
592
|
-
|
|
610
|
+
**OpenSpec Skill** (`openspec-skill.md`) — Skill for working with OpenSpec specifications:
|
|
611
|
+
- Semantic spec search with `search_specs`
|
|
612
|
+
- List domains with `list_spec_domains`
|
|
613
|
+
- Navigate requirements and scenarios
|
|
593
614
|
|
|
594
615
|
### Tools
|
|
595
616
|
|
|
@@ -600,7 +621,7 @@ All tools run on **pure static analysis** -- no LLM quota consumed.
|
|
|
600
621
|
| Tool | Description | Requires prior analysis |
|
|
601
622
|
|------|-------------|:---:|
|
|
602
623
|
| `analyze_codebase` | Run full static analysis: repo structure, dependency graph, call graph (hub functions, entry points, layer violations), and top refactoring priorities. Results cached for 1 hour (`force: true` to bypass). | No |
|
|
603
|
-
| `get_call_graph` | Hub functions (high fan-in), entry points (no internal callers), and architectural layer violations. Supports TypeScript, JavaScript, Python, Go, Rust, Ruby, Java
|
|
624
|
+
| `get_call_graph` | Hub functions (high fan-in), entry points (no internal callers), and architectural layer violations. Supports TypeScript, JavaScript, Python, Go, Rust, Ruby, Java, C++. | Yes |
|
|
604
625
|
| `get_signatures` | Compact function/class signatures per file. Filter by path substring with `filePattern`. Useful for understanding a module's public API without reading full source. | Yes |
|
|
605
626
|
| `get_duplicate_report` | Detect duplicate code: Type 1 (exact clones), Type 2 (structural -- renamed variables), Type 3 (near-clones with Jaccard similarity >= 0.7). Groups sorted by impact. | Yes |
|
|
606
627
|
|
|
@@ -613,6 +634,7 @@ All tools run on **pure static analysis** -- no LLM quota consumed.
|
|
|
613
634
|
| `get_low_risk_refactor_candidates` | Safest functions to refactor first: low fan-in, low fan-out, not a hub, no cyclic involvement. Best starting point for incremental, low-risk sessions. | Yes |
|
|
614
635
|
| `get_leaf_functions` | Functions that make no internal calls (leaves of the call graph). Zero downstream blast radius. Sorted by fan-in by default -- most-called leaves have the best unit-test ROI. | Yes |
|
|
615
636
|
| `get_critical_hubs` | Highest-impact hub functions ranked by criticality. Each hub gets a stability score (0-100) and a recommended approach: extract, split, facade, or delegate. | Yes |
|
|
637
|
+
| `get_god_functions` | Detect god functions (high fan-out, likely orchestrators) in the project or in a specific file, and return their call-graph neighborhood. Use this to identify which functions need to be refactored and understand what logical blocks to extract. | Yes |
|
|
616
638
|
|
|
617
639
|
**Navigation**
|
|
618
640
|
|
|
@@ -630,6 +652,8 @@ All tools run on **pure static analysis** -- no LLM quota consumed.
|
|
|
630
652
|
|------|-------------|:---:|
|
|
631
653
|
| `get_mapping` | Requirement->function mapping produced by `spec-gen generate`. Shows which functions implement which spec requirements, confidence level, and orphan functions with no spec coverage. | Yes (generate) |
|
|
632
654
|
| `check_spec_drift` | Detect code changes not reflected in OpenSpec specs. Compares git-changed files against spec coverage maps. Issues: gap / stale / uncovered / orphaned-spec / adr-gap. | Yes (generate) |
|
|
655
|
+
| `search_specs` | Semantic search over OpenSpec specifications to find requirements, design notes, and architecture decisions by meaning. Returns linked source files for graph highlighting. Use this when asked "which spec covers X?" or "where should we implement Z?". Requires a spec index built with `spec-gen analyze --embed` or `--reindex-specs`. | Yes (generate) |
|
|
656
|
+
| `list_spec_domains` | List all OpenSpec domains available in this project. Use this to discover what domains exist before doing a targeted `search_specs` call. | Yes (generate) |
|
|
633
657
|
|
|
634
658
|
### Parameters
|
|
635
659
|
|
|
@@ -683,6 +707,11 @@ failOn string Minimum severity to report: "error" | "warning" | "info" (d
|
|
|
683
707
|
maxFiles number Max changed files to analyze (default: 100)
|
|
684
708
|
```
|
|
685
709
|
|
|
710
|
+
**`list_spec_domains`**
|
|
711
|
+
```
|
|
712
|
+
directory string Absolute path to the project directory
|
|
713
|
+
```
|
|
714
|
+
|
|
686
715
|
**`analyze_impact`**
|
|
687
716
|
```
|
|
688
717
|
directory string Absolute path to the project directory
|
|
@@ -725,11 +754,19 @@ directory string Absolute path to the project directory
|
|
|
725
754
|
filePath string Path to the file, relative to the project directory
|
|
726
755
|
```
|
|
727
756
|
|
|
757
|
+
**`get_god_functions`**
|
|
758
|
+
```
|
|
759
|
+
directory string Absolute path to the project directory
|
|
760
|
+
filePath string Optional: restrict search to this file (relative path)
|
|
761
|
+
fanOutThreshold number Minimum fan-out to be considered a god function (default: 8)
|
|
762
|
+
```
|
|
763
|
+
|
|
728
764
|
**`suggest_insertion_points`**
|
|
729
765
|
```
|
|
730
|
-
directory
|
|
731
|
-
|
|
732
|
-
limit
|
|
766
|
+
directory string Absolute path to the project directory
|
|
767
|
+
description string Natural-language description of the feature to implement
|
|
768
|
+
limit number Max candidates to return (default: 5)
|
|
769
|
+
language string Filter by language: "TypeScript" | "Python" | "Go" | ...
|
|
733
770
|
```
|
|
734
771
|
|
|
735
772
|
**`search_code`**
|
|
@@ -741,6 +778,15 @@ language string Filter by language: "TypeScript" | "Python" | "Go" | ...
|
|
|
741
778
|
minFanIn number Only return functions with at least this many callers
|
|
742
779
|
```
|
|
743
780
|
|
|
781
|
+
**`search_specs`**
|
|
782
|
+
```
|
|
783
|
+
directory string Absolute path to the project directory
|
|
784
|
+
query string Natural language query, e.g. "email validation workflow"
|
|
785
|
+
limit number Maximum number of results to return (default: 10)
|
|
786
|
+
domain string Filter by domain name (e.g. "auth", "analyzer")
|
|
787
|
+
section string Filter by section type: "requirements" | "purpose" | "design" | "architecture" | "entities"
|
|
788
|
+
```
|
|
789
|
+
|
|
744
790
|
### Typical workflow
|
|
745
791
|
|
|
746
792
|
**Scenario A -- Initial exploration**
|
|
@@ -879,7 +925,7 @@ Static analysis output is stored in `.spec-gen/analysis/`:
|
|
|
879
925
|
| File | Description |
|
|
880
926
|
|------|-------------|
|
|
881
927
|
| `repo-structure.json` | Project structure and metadata |
|
|
882
|
-
| `dependency-graph.json` | Import/export relationships |
|
|
928
|
+
| `dependency-graph.json` | Import/export relationships and HTTP cross-language edges (JS/TS → Python) |
|
|
883
929
|
| `llm-context.json` | Context prepared for LLM (signatures, call graph) |
|
|
884
930
|
| `dependencies.mermaid` | Visual dependency graph |
|
|
885
931
|
| `SUMMARY.md` | Human-readable analysis summary |
|
|
@@ -913,11 +959,14 @@ spec-gen analyze --embed
|
|
|
913
959
|
{
|
|
914
960
|
"embedding": {
|
|
915
961
|
"baseUrl": "http://localhost:11434/v1",
|
|
916
|
-
"model": "nomic-embed-text"
|
|
962
|
+
"model": "nomic-embed-text",
|
|
963
|
+
"batchSize": 64
|
|
917
964
|
}
|
|
918
965
|
}
|
|
919
966
|
```
|
|
920
967
|
|
|
968
|
+
- `batchSize`: Number of texts to embed per API call (default: 64)
|
|
969
|
+
|
|
921
970
|
The index is stored in `.spec-gen/analysis/vector-index/` and is automatically used by the viewer's search bar and the `search_code` / `suggest_insertion_points` MCP tools.
|
|
922
971
|
|
|
923
972
|
## Configuration
|
|
@@ -952,6 +1001,9 @@ The index is stored in `.spec-gen/analysis/vector-index/` and is automatically u
|
|
|
952
1001
|
| `OPENAI_COMPAT_API_KEY` | `openai-compat` | API key for OpenAI-compatible server |
|
|
953
1002
|
| `OPENAI_COMPAT_BASE_URL` | `openai-compat` | Base URL, e.g. `https://api.mistral.ai/v1` |
|
|
954
1003
|
| `GEMINI_API_KEY` | `gemini` | Google Gemini API key |
|
|
1004
|
+
| `EMBED_BASE_URL` | embedding | Base URL for the embedding API (e.g. `http://localhost:11434/v1`) |
|
|
1005
|
+
| `EMBED_MODEL` | embedding | Embedding model name (e.g. `nomic-embed-text`) |
|
|
1006
|
+
| `EMBED_API_KEY` | embedding | API key for the embedding service (defaults to `OPENAI_API_KEY`) |
|
|
955
1007
|
| `DEBUG` | -- | Enable stack traces on errors |
|
|
956
1008
|
| `CI` | -- | Auto-detected; enables timestamps in output |
|
|
957
1009
|
|
|
@@ -977,6 +1029,7 @@ The index is stored in `.spec-gen/analysis/vector-index/` and is automatically u
|
|
|
977
1029
|
| Rust | Full | Full |
|
|
978
1030
|
| Ruby | Full | Full |
|
|
979
1031
|
| Java | Full | Full |
|
|
1032
|
+
| C++ | Full | Full |
|
|
980
1033
|
|
|
981
1034
|
TypeScript projects get the best results due to richer type information.
|
|
982
1035
|
|
|
@@ -1000,7 +1053,7 @@ spec-gen init && spec-gen analyze && spec-gen generate && spec-gen drift --insta
|
|
|
1000
1053
|
spec-gen exposes a typed Node.js API for integration into other tools (like [OpenSpec CLI](https://github.com/Fission-AI/OpenSpec)). Every CLI command has a corresponding API function that returns structured results instead of printing to the console.
|
|
1001
1054
|
|
|
1002
1055
|
```bash
|
|
1003
|
-
npm install spec-gen
|
|
1056
|
+
npm install spec-gen-cli
|
|
1004
1057
|
```
|
|
1005
1058
|
|
|
1006
1059
|
```typescript
|
|
@@ -1041,11 +1094,44 @@ console.log(`Analyzed ${analysis.repoMap.summary.analyzedFiles} files`);
|
|
|
1041
1094
|
| `specGenVerify(options?)` | Verify spec accuracy | Yes |
|
|
1042
1095
|
| `specGenDrift(options?)` | Detect spec-to-code drift | No* |
|
|
1043
1096
|
| `specGenRun(options?)` | Full pipeline: init + analyze + generate | Yes |
|
|
1097
|
+
| `specGenGetSpecRequirements(options?)` | Read requirement blocks from generated specs | No |
|
|
1044
1098
|
|
|
1045
1099
|
\* `specGenDrift` requires an API key only when `llmEnhanced: true`.
|
|
1046
1100
|
|
|
1047
1101
|
All functions accept an optional `onProgress` callback for status updates and throw errors instead of calling `process.exit`. See [src/api/types.ts](src/api/types.ts) for full option and result type definitions.
|
|
1048
1102
|
|
|
1103
|
+
### Error handling
|
|
1104
|
+
|
|
1105
|
+
All API functions throw `Error` on failure. Wrap calls in try-catch for production use:
|
|
1106
|
+
|
|
1107
|
+
```typescript
|
|
1108
|
+
import { specGenRun } from 'spec-gen-cli';
|
|
1109
|
+
|
|
1110
|
+
try {
|
|
1111
|
+
const result = await specGenRun({ rootPath: '/path/to/project' });
|
|
1112
|
+
console.log(`Done — ${result.generation.report.filesWritten.length} specs written`);
|
|
1113
|
+
} catch (err) {
|
|
1114
|
+
if ((err as Error).message.includes('API key')) {
|
|
1115
|
+
console.error('Set ANTHROPIC_API_KEY or OPENAI_API_KEY');
|
|
1116
|
+
} else {
|
|
1117
|
+
console.error('spec-gen failed:', (err as Error).message);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1122
|
+
### Reading generated spec requirements
|
|
1123
|
+
|
|
1124
|
+
After running `specGenGenerate`, you can programmatically query the requirement-to-function mapping:
|
|
1125
|
+
|
|
1126
|
+
```typescript
|
|
1127
|
+
import { specGenGetSpecRequirements } from 'spec-gen-cli';
|
|
1128
|
+
|
|
1129
|
+
const { requirements } = await specGenGetSpecRequirements({ rootPath: '/path/to/project' });
|
|
1130
|
+
for (const [key, req] of Object.entries(requirements)) {
|
|
1131
|
+
console.log(`${key}: ${req.title} (${req.specFile})`);
|
|
1132
|
+
}
|
|
1133
|
+
```
|
|
1134
|
+
|
|
1049
1135
|
## Examples
|
|
1050
1136
|
|
|
1051
1137
|
| Example | Description |
|
|
@@ -1060,11 +1146,11 @@ All functions accept an optional `onProgress` callback for status updates and th
|
|
|
1060
1146
|
npm install # Install dependencies
|
|
1061
1147
|
npm run dev # Development mode (watch)
|
|
1062
1148
|
npm run build # Build
|
|
1063
|
-
npm run test:run # Run tests (
|
|
1149
|
+
npm run test:run # Run tests (1526 unit tests)
|
|
1064
1150
|
npm run typecheck # Type check
|
|
1065
1151
|
```
|
|
1066
1152
|
|
|
1067
|
-
|
|
1153
|
+
1526 unit tests covering static analysis, call graph, refactor analysis, spec mapping, drift detection, LLM enhancement, ADR generation, and the full CLI.
|
|
1068
1154
|
|
|
1069
1155
|
## Links
|
|
1070
1156
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/api/analyze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/api/analyze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAoB,MAAM,YAAY,CAAC;AAiCrF;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,aAAa,CAAC,CA4H5F"}
|
package/dist/api/analyze.js
CHANGED
|
@@ -5,22 +5,33 @@
|
|
|
5
5
|
* No side effects (no process.exit, no console.log).
|
|
6
6
|
*/
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
import {
|
|
8
|
+
import { readFile, stat, mkdir, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { ANALYSIS_STALE_THRESHOLD_MS, DEFAULT_MAX_FILES, SPEC_GEN_ANALYSIS_REL_PATH, ARTIFACT_REPO_STRUCTURE, ARTIFACT_DEPENDENCY_GRAPH, ARTIFACT_LLM_CONTEXT } from '../constants.js';
|
|
10
|
+
import { fileExists, readJsonFile } from '../utils/command-helpers.js';
|
|
9
11
|
import { readSpecGenConfig } from '../core/services/config-manager.js';
|
|
10
12
|
import { RepositoryMapper } from '../core/analyzer/repository-mapper.js';
|
|
11
|
-
import { DependencyGraphBuilder } from '../core/analyzer/dependency-graph.js';
|
|
12
|
-
import { AnalysisArtifactGenerator } from '../core/analyzer/artifact-generator.js';
|
|
13
|
+
import { DependencyGraphBuilder, } from '../core/analyzer/dependency-graph.js';
|
|
14
|
+
import { AnalysisArtifactGenerator, repoStructureToRepoMap } from '../core/analyzer/artifact-generator.js';
|
|
13
15
|
function progress(onProgress, step, status, detail) {
|
|
14
16
|
onProgress?.({ phase: 'analyze', step, status, detail });
|
|
15
17
|
}
|
|
16
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Load cached analysis artifacts from disk.
|
|
20
|
+
* All four artifact files are saved by AnalysisArtifactGenerator.generateAndSave().
|
|
21
|
+
*/
|
|
22
|
+
async function loadCachedArtifacts(outputPath, repoStructure) {
|
|
23
|
+
const llmContext = await readJsonFile(join(outputPath, ARTIFACT_LLM_CONTEXT), ARTIFACT_LLM_CONTEXT) ?? { phase1_survey: { purpose: '', files: [] }, phase2_deep: { purpose: '', files: [] }, phase3_validation: { purpose: '', files: [] } };
|
|
24
|
+
let summaryMarkdown = '';
|
|
25
|
+
let dependencyDiagram = '';
|
|
17
26
|
try {
|
|
18
|
-
await
|
|
19
|
-
return true;
|
|
27
|
+
summaryMarkdown = await readFile(join(outputPath, 'SUMMARY.md'), 'utf-8');
|
|
20
28
|
}
|
|
21
|
-
catch {
|
|
22
|
-
|
|
29
|
+
catch { /* optional */ }
|
|
30
|
+
try {
|
|
31
|
+
dependencyDiagram = await readFile(join(outputPath, 'dependencies.mermaid'), 'utf-8');
|
|
23
32
|
}
|
|
33
|
+
catch { /* optional */ }
|
|
34
|
+
return { repoStructure, summaryMarkdown, dependencyDiagram, llmContext };
|
|
24
35
|
}
|
|
25
36
|
/**
|
|
26
37
|
* Run static analysis on the codebase.
|
|
@@ -33,10 +44,11 @@ async function fileExists(path) {
|
|
|
33
44
|
export async function specGenAnalyze(options = {}) {
|
|
34
45
|
const startTime = Date.now();
|
|
35
46
|
const rootPath = options.rootPath ?? process.cwd();
|
|
36
|
-
const maxFiles = options.maxFiles ??
|
|
47
|
+
const maxFiles = options.maxFiles ?? DEFAULT_MAX_FILES;
|
|
37
48
|
const excludePatterns = options.excludePatterns ?? [];
|
|
49
|
+
const includePatterns = options.includePatterns ?? [];
|
|
38
50
|
const force = options.force ?? false;
|
|
39
|
-
const outputRelPath = options.outputPath ??
|
|
51
|
+
const outputRelPath = options.outputPath ?? `${SPEC_GEN_ANALYSIS_REL_PATH}/`;
|
|
40
52
|
const outputPath = join(rootPath, outputRelPath);
|
|
41
53
|
const { onProgress } = options;
|
|
42
54
|
// Validate config exists
|
|
@@ -46,31 +58,47 @@ export async function specGenAnalyze(options = {}) {
|
|
|
46
58
|
}
|
|
47
59
|
// Check for existing recent analysis
|
|
48
60
|
if (!force) {
|
|
49
|
-
const repoStructurePath = join(outputPath,
|
|
61
|
+
const repoStructurePath = join(outputPath, ARTIFACT_REPO_STRUCTURE);
|
|
50
62
|
if (await fileExists(repoStructurePath)) {
|
|
51
63
|
const stats = await stat(repoStructurePath);
|
|
52
64
|
const age = Date.now() - stats.mtime.getTime();
|
|
53
|
-
|
|
54
|
-
if (age < oneHour) {
|
|
65
|
+
if (age < ANALYSIS_STALE_THRESHOLD_MS) {
|
|
55
66
|
progress(onProgress, 'Recent analysis exists', 'skip', `${Math.floor(age / 60000)} minutes old`);
|
|
56
67
|
// Load and return existing analysis
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const depGraphPath = join(outputPath, 'dependency-graph.json');
|
|
61
|
-
let depGraph;
|
|
62
|
-
if (await fileExists(depGraphPath)) {
|
|
63
|
-
const depGraphContent = await readFile(depGraphPath, 'utf-8');
|
|
64
|
-
depGraph = JSON.parse(depGraphContent);
|
|
68
|
+
const repoStructure = await readJsonFile(repoStructurePath, ARTIFACT_REPO_STRUCTURE);
|
|
69
|
+
if (!repoStructure) {
|
|
70
|
+
throw new Error(`Failed to load ${ARTIFACT_REPO_STRUCTURE} — run spec-gen analyze --force to regenerate`);
|
|
65
71
|
}
|
|
72
|
+
const depGraph = await readJsonFile(join(outputPath, ARTIFACT_DEPENDENCY_GRAPH), ARTIFACT_DEPENDENCY_GRAPH) ?? undefined;
|
|
66
73
|
return {
|
|
67
|
-
repoMap: repoStructure,
|
|
74
|
+
repoMap: repoStructureToRepoMap(repoStructure),
|
|
68
75
|
depGraph: depGraph ?? {
|
|
69
|
-
nodes: [],
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
nodes: [],
|
|
77
|
+
edges: [],
|
|
78
|
+
clusters: [],
|
|
79
|
+
cycles: [],
|
|
80
|
+
structuralClusters: [],
|
|
81
|
+
rankings: {
|
|
82
|
+
byImportance: [],
|
|
83
|
+
byConnectivity: [],
|
|
84
|
+
clusterCenters: [],
|
|
85
|
+
leafNodes: [],
|
|
86
|
+
bridgeNodes: [],
|
|
87
|
+
orphanNodes: [],
|
|
88
|
+
},
|
|
89
|
+
statistics: {
|
|
90
|
+
nodeCount: 0,
|
|
91
|
+
edgeCount: 0,
|
|
92
|
+
importEdgeCount: 0,
|
|
93
|
+
httpEdgeCount: 0,
|
|
94
|
+
clusterCount: 0,
|
|
95
|
+
cycleCount: 0,
|
|
96
|
+
avgDegree: 0,
|
|
97
|
+
density: 0,
|
|
98
|
+
structuralClusterCount: 0,
|
|
99
|
+
},
|
|
72
100
|
},
|
|
73
|
-
artifacts:
|
|
101
|
+
artifacts: await loadCachedArtifacts(outputPath, repoStructure),
|
|
74
102
|
duration: Date.now() - startTime,
|
|
75
103
|
};
|
|
76
104
|
}
|
|
@@ -83,6 +111,7 @@ export async function specGenAnalyze(options = {}) {
|
|
|
83
111
|
const mapper = new RepositoryMapper(rootPath, {
|
|
84
112
|
maxFiles,
|
|
85
113
|
excludePatterns: excludePatterns.length > 0 ? excludePatterns : undefined,
|
|
114
|
+
includePatterns: includePatterns.length > 0 ? includePatterns : undefined,
|
|
86
115
|
});
|
|
87
116
|
const repoMap = await mapper.map();
|
|
88
117
|
progress(onProgress, 'Scanning directory structure', 'complete', `${repoMap.summary.analyzedFiles} files`);
|
|
@@ -101,7 +130,7 @@ export async function specGenAnalyze(options = {}) {
|
|
|
101
130
|
});
|
|
102
131
|
const artifacts = await artifactGenerator.generateAndSave(repoMap, depGraph);
|
|
103
132
|
// Save dependency graph
|
|
104
|
-
await writeFile(join(outputPath,
|
|
133
|
+
await writeFile(join(outputPath, ARTIFACT_DEPENDENCY_GRAPH), JSON.stringify(depGraph, null, 2));
|
|
105
134
|
progress(onProgress, 'Generating analysis artifacts', 'complete');
|
|
106
135
|
const duration = Date.now() - startTime;
|
|
107
136
|
return { repoMap, depGraph, artifacts, duration };
|
package/dist/api/analyze.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../src/api/analyze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../src/api/analyze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,2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G,QAAQ,CAAC,UAAU,CAAC,SAAS,WAAW,QAAQ,CAAC,UAAU,CAAC,SAAS,QAAQ,CACjF,CAAC;IAEF,8BAA8B;IAC9B,QAAQ,CAAC,UAAU,EAAE,+BAA+B,EAAE,OAAO,CAAC,CAAC;IAC/D,MAAM,iBAAiB,GAAG,IAAI,yBAAyB,CAAC;QACtD,OAAO,EAAE,QAAQ;QACjB,SAAS,EAAE,UAAU;QACrB,oBAAoB,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;QAClF,kBAAkB,EAAE,CAAC;KACtB,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE7E,wBAAwB;IACxB,MAAM,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,yBAAyB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChG,QAAQ,CAAC,UAAU,EAAE,+BAA+B,EAAE,UAAU,CAAC,CAAC;IAElE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACxC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACpD,CAAC"}
|
package/dist/api/drift.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/api/drift.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/api/drift.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,YAAY,CAAC;AAMpE;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,WAAW,CAAC,CAsItF"}
|