legacyver 2.1.0 → 2.1.2

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 (126) hide show
  1. package/.agent/skills/openspec-apply-change/SKILL.md +156 -0
  2. package/.agent/skills/openspec-archive-change/SKILL.md +114 -0
  3. package/.agent/skills/openspec-bulk-archive-change/SKILL.md +246 -0
  4. package/.agent/skills/openspec-continue-change/SKILL.md +118 -0
  5. package/.agent/skills/openspec-explore/SKILL.md +290 -0
  6. package/.agent/skills/openspec-ff-change/SKILL.md +101 -0
  7. package/.agent/skills/openspec-new-change/SKILL.md +74 -0
  8. package/.agent/skills/openspec-onboard/SKILL.md +529 -0
  9. package/.agent/skills/openspec-sync-specs/SKILL.md +138 -0
  10. package/.agent/skills/openspec-verify-change/SKILL.md +168 -0
  11. package/.agent/workflows/opsx-apply.md +149 -0
  12. package/.agent/workflows/opsx-archive.md +154 -0
  13. package/.agent/workflows/opsx-bulk-archive.md +239 -0
  14. package/.agent/workflows/opsx-continue.md +111 -0
  15. package/.agent/workflows/opsx-explore.md +171 -0
  16. package/.agent/workflows/opsx-ff.md +91 -0
  17. package/.agent/workflows/opsx-new.md +66 -0
  18. package/.agent/workflows/opsx-onboard.md +522 -0
  19. package/.agent/workflows/opsx-sync.md +131 -0
  20. package/.agent/workflows/opsx-verify.md +161 -0
  21. package/.github/prompts/opsx-apply.prompt.md +149 -0
  22. package/.github/prompts/opsx-archive.prompt.md +154 -0
  23. package/.github/prompts/opsx-bulk-archive.prompt.md +239 -0
  24. package/.github/prompts/opsx-continue.prompt.md +111 -0
  25. package/.github/prompts/opsx-explore.prompt.md +171 -0
  26. package/.github/prompts/opsx-ff.prompt.md +91 -0
  27. package/.github/prompts/opsx-new.prompt.md +66 -0
  28. package/.github/prompts/opsx-onboard.prompt.md +522 -0
  29. package/.github/prompts/opsx-sync.prompt.md +131 -0
  30. package/.github/prompts/opsx-verify.prompt.md +161 -0
  31. package/.github/skills/openspec-apply-change/SKILL.md +156 -0
  32. package/.github/skills/openspec-archive-change/SKILL.md +114 -0
  33. package/.github/skills/openspec-bulk-archive-change/SKILL.md +246 -0
  34. package/.github/skills/openspec-continue-change/SKILL.md +118 -0
  35. package/.github/skills/openspec-explore/SKILL.md +290 -0
  36. package/.github/skills/openspec-ff-change/SKILL.md +101 -0
  37. package/.github/skills/openspec-new-change/SKILL.md +74 -0
  38. package/.github/skills/openspec-onboard/SKILL.md +529 -0
  39. package/.github/skills/openspec-sync-specs/SKILL.md +138 -0
  40. package/.github/skills/openspec-verify-change/SKILL.md +168 -0
  41. package/.legacyverignore.example +43 -0
  42. package/.legacyverrc +7 -0
  43. package/.opencode/command/opsx-apply.md +149 -0
  44. package/.opencode/command/opsx-archive.md +154 -0
  45. package/.opencode/command/opsx-bulk-archive.md +239 -0
  46. package/.opencode/command/opsx-continue.md +111 -0
  47. package/.opencode/command/opsx-explore.md +171 -0
  48. package/.opencode/command/opsx-ff.md +91 -0
  49. package/.opencode/command/opsx-new.md +66 -0
  50. package/.opencode/command/opsx-onboard.md +522 -0
  51. package/.opencode/command/opsx-sync.md +131 -0
  52. package/.opencode/command/opsx-verify.md +161 -0
  53. package/.opencode/skills/openspec-apply-change/SKILL.md +156 -0
  54. package/.opencode/skills/openspec-archive-change/SKILL.md +114 -0
  55. package/.opencode/skills/openspec-bulk-archive-change/SKILL.md +246 -0
  56. package/.opencode/skills/openspec-continue-change/SKILL.md +118 -0
  57. package/.opencode/skills/openspec-explore/SKILL.md +290 -0
  58. package/.opencode/skills/openspec-ff-change/SKILL.md +101 -0
  59. package/.opencode/skills/openspec-new-change/SKILL.md +74 -0
  60. package/.opencode/skills/openspec-onboard/SKILL.md +529 -0
  61. package/.opencode/skills/openspec-sync-specs/SKILL.md +138 -0
  62. package/.opencode/skills/openspec-verify-change/SKILL.md +168 -0
  63. package/LICENSE +1 -1
  64. package/README.md +128 -83
  65. package/bin/legacyver.js +48 -25
  66. package/legacyver-docs/SUMMARY.md +3 -0
  67. package/legacyver-docs/components.md +57 -0
  68. package/legacyver-docs/index.md +15 -0
  69. package/nul +2 -0
  70. package/package.json +23 -25
  71. package/src/cache/hash.js +9 -10
  72. package/src/cache/index.js +43 -65
  73. package/src/cli/commands/analyze.js +212 -190
  74. package/src/cli/commands/cache.js +15 -35
  75. package/src/cli/commands/init.js +63 -107
  76. package/src/cli/commands/providers.js +56 -81
  77. package/src/cli/commands/version.js +7 -10
  78. package/src/cli/ui.js +58 -77
  79. package/src/crawler/filters.js +41 -40
  80. package/src/crawler/index.js +52 -36
  81. package/src/crawler/manifest.js +31 -43
  82. package/src/crawler/walk.js +32 -38
  83. package/src/llm/chunker.js +34 -56
  84. package/src/llm/cost-estimator.js +68 -51
  85. package/src/llm/free-model.js +67 -0
  86. package/src/llm/index.js +22 -43
  87. package/src/llm/prompts.js +45 -33
  88. package/src/llm/providers/gemini.js +94 -0
  89. package/src/llm/providers/groq.js +55 -40
  90. package/src/llm/providers/ollama.js +38 -65
  91. package/src/llm/providers/openrouter.js +67 -0
  92. package/src/llm/queue.js +59 -88
  93. package/src/llm/re-prompter.js +41 -0
  94. package/src/llm/validator.js +72 -0
  95. package/src/parser/ast/generic.js +45 -222
  96. package/src/parser/ast/go.js +86 -205
  97. package/src/parser/ast/java.js +76 -146
  98. package/src/parser/ast/javascript.js +173 -241
  99. package/src/parser/ast/laravel/blade.js +56 -0
  100. package/src/parser/ast/laravel/classifier.js +30 -0
  101. package/src/parser/ast/laravel/controller.js +35 -0
  102. package/src/parser/ast/laravel/index.js +54 -0
  103. package/src/parser/ast/laravel/model.js +41 -0
  104. package/src/parser/ast/laravel/provider.js +28 -0
  105. package/src/parser/ast/laravel/routes.js +45 -0
  106. package/src/parser/ast/php.js +129 -0
  107. package/src/parser/ast/python.js +76 -199
  108. package/src/parser/ast/typescript.js +10 -244
  109. package/src/parser/body-extractor.js +40 -0
  110. package/src/parser/call-graph.js +50 -67
  111. package/src/parser/complexity-scorer.js +59 -0
  112. package/src/parser/index.js +61 -86
  113. package/src/parser/pattern-detector.js +71 -0
  114. package/src/parser/pkg-builder.js +36 -83
  115. package/src/renderer/html.js +63 -135
  116. package/src/renderer/index.js +23 -35
  117. package/src/renderer/json.js +17 -35
  118. package/src/renderer/markdown.js +83 -117
  119. package/src/utils/config.js +52 -53
  120. package/src/utils/errors.js +26 -41
  121. package/src/utils/logger.js +32 -53
  122. package/src/cli/flags.js +0 -87
  123. package/src/llm/providers/anthropic.js +0 -57
  124. package/src/llm/providers/google.js +0 -65
  125. package/src/llm/providers/openai.js +0 -52
  126. package/src/parser/ast/tree-sitter-init.js +0 -80
@@ -0,0 +1,168 @@
1
+ ---
2
+ name: openspec-verify-change
3
+ description: Verify implementation matches change artifacts. Use when the user wants to validate that implementation is complete, correct, and coherent before archiving.
4
+ license: MIT
5
+ compatibility: Requires openspec CLI.
6
+ metadata:
7
+ author: openspec
8
+ version: "1.0"
9
+ generatedBy: "1.1.1"
10
+ ---
11
+
12
+ Verify that an implementation matches the change artifacts (specs, tasks, design).
13
+
14
+ **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
15
+
16
+ **Steps**
17
+
18
+ 1. **If no change name provided, prompt for selection**
19
+
20
+ Run `openspec list --json` to get available changes. Use the **AskUserQuestion tool** to let the user select.
21
+
22
+ Show changes that have implementation tasks (tasks artifact exists).
23
+ Include the schema used for each change if available.
24
+ Mark changes with incomplete tasks as "(In Progress)".
25
+
26
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
27
+
28
+ 2. **Check status to understand the schema**
29
+ ```bash
30
+ openspec status --change "<name>" --json
31
+ ```
32
+ Parse the JSON to understand:
33
+ - `schemaName`: The workflow being used (e.g., "spec-driven")
34
+ - Which artifacts exist for this change
35
+
36
+ 3. **Get the change directory and load artifacts**
37
+
38
+ ```bash
39
+ openspec instructions apply --change "<name>" --json
40
+ ```
41
+
42
+ This returns the change directory and context files. Read all available artifacts from `contextFiles`.
43
+
44
+ 4. **Initialize verification report structure**
45
+
46
+ Create a report structure with three dimensions:
47
+ - **Completeness**: Track tasks and spec coverage
48
+ - **Correctness**: Track requirement implementation and scenario coverage
49
+ - **Coherence**: Track design adherence and pattern consistency
50
+
51
+ Each dimension can have CRITICAL, WARNING, or SUGGESTION issues.
52
+
53
+ 5. **Verify Completeness**
54
+
55
+ **Task Completion**:
56
+ - If tasks.md exists in contextFiles, read it
57
+ - Parse checkboxes: `- [ ]` (incomplete) vs `- [x]` (complete)
58
+ - Count complete vs total tasks
59
+ - If incomplete tasks exist:
60
+ - Add CRITICAL issue for each incomplete task
61
+ - Recommendation: "Complete task: <description>" or "Mark as done if already implemented"
62
+
63
+ **Spec Coverage**:
64
+ - If delta specs exist in `openspec/changes/<name>/specs/`:
65
+ - Extract all requirements (marked with "### Requirement:")
66
+ - For each requirement:
67
+ - Search codebase for keywords related to the requirement
68
+ - Assess if implementation likely exists
69
+ - If requirements appear unimplemented:
70
+ - Add CRITICAL issue: "Requirement not found: <requirement name>"
71
+ - Recommendation: "Implement requirement X: <description>"
72
+
73
+ 6. **Verify Correctness**
74
+
75
+ **Requirement Implementation Mapping**:
76
+ - For each requirement from delta specs:
77
+ - Search codebase for implementation evidence
78
+ - If found, note file paths and line ranges
79
+ - Assess if implementation matches requirement intent
80
+ - If divergence detected:
81
+ - Add WARNING: "Implementation may diverge from spec: <details>"
82
+ - Recommendation: "Review <file>:<lines> against requirement X"
83
+
84
+ **Scenario Coverage**:
85
+ - For each scenario in delta specs (marked with "#### Scenario:"):
86
+ - Check if conditions are handled in code
87
+ - Check if tests exist covering the scenario
88
+ - If scenario appears uncovered:
89
+ - Add WARNING: "Scenario not covered: <scenario name>"
90
+ - Recommendation: "Add test or implementation for scenario: <description>"
91
+
92
+ 7. **Verify Coherence**
93
+
94
+ **Design Adherence**:
95
+ - If design.md exists in contextFiles:
96
+ - Extract key decisions (look for sections like "Decision:", "Approach:", "Architecture:")
97
+ - Verify implementation follows those decisions
98
+ - If contradiction detected:
99
+ - Add WARNING: "Design decision not followed: <decision>"
100
+ - Recommendation: "Update implementation or revise design.md to match reality"
101
+ - If no design.md: Skip design adherence check, note "No design.md to verify against"
102
+
103
+ **Code Pattern Consistency**:
104
+ - Review new code for consistency with project patterns
105
+ - Check file naming, directory structure, coding style
106
+ - If significant deviations found:
107
+ - Add SUGGESTION: "Code pattern deviation: <details>"
108
+ - Recommendation: "Consider following project pattern: <example>"
109
+
110
+ 8. **Generate Verification Report**
111
+
112
+ **Summary Scorecard**:
113
+ ```
114
+ ## Verification Report: <change-name>
115
+
116
+ ### Summary
117
+ | Dimension | Status |
118
+ |--------------|------------------|
119
+ | Completeness | X/Y tasks, N reqs|
120
+ | Correctness | M/N reqs covered |
121
+ | Coherence | Followed/Issues |
122
+ ```
123
+
124
+ **Issues by Priority**:
125
+
126
+ 1. **CRITICAL** (Must fix before archive):
127
+ - Incomplete tasks
128
+ - Missing requirement implementations
129
+ - Each with specific, actionable recommendation
130
+
131
+ 2. **WARNING** (Should fix):
132
+ - Spec/design divergences
133
+ - Missing scenario coverage
134
+ - Each with specific recommendation
135
+
136
+ 3. **SUGGESTION** (Nice to fix):
137
+ - Pattern inconsistencies
138
+ - Minor improvements
139
+ - Each with specific recommendation
140
+
141
+ **Final Assessment**:
142
+ - If CRITICAL issues: "X critical issue(s) found. Fix before archiving."
143
+ - If only warnings: "No critical issues. Y warning(s) to consider. Ready for archive (with noted improvements)."
144
+ - If all clear: "All checks passed. Ready for archive."
145
+
146
+ **Verification Heuristics**
147
+
148
+ - **Completeness**: Focus on objective checklist items (checkboxes, requirements list)
149
+ - **Correctness**: Use keyword search, file path analysis, reasonable inference - don't require perfect certainty
150
+ - **Coherence**: Look for glaring inconsistencies, don't nitpick style
151
+ - **False Positives**: When uncertain, prefer SUGGESTION over WARNING, WARNING over CRITICAL
152
+ - **Actionability**: Every issue must have a specific recommendation with file/line references where applicable
153
+
154
+ **Graceful Degradation**
155
+
156
+ - If only tasks.md exists: verify task completion only, skip spec/design checks
157
+ - If tasks + specs exist: verify completeness and correctness, skip design
158
+ - If full artifacts: verify all three dimensions
159
+ - Always note which checks were skipped and why
160
+
161
+ **Output Format**
162
+
163
+ Use clear markdown with:
164
+ - Table for summary scorecard
165
+ - Grouped lists for issues (CRITICAL/WARNING/SUGGESTION)
166
+ - Code references in format: `file.ts:123`
167
+ - Specific, actionable recommendations
168
+ - No vague suggestions like "consider reviewing"
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 legacyver contributors
3
+ Copyright (c) 2024 Legacyver Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,8 +1,14 @@
1
- # legacyver
1
+ # Legacyver
2
2
 
3
- Generate technical documentation from undocumented or legacy codebases using AST parsing and LLMs.
3
+ Auto-generate technical documentation for legacy and undocumented codebases using AST parsing + LLMs.
4
4
 
5
- Legacyver crawls your source code, extracts structural facts with AST parsers (Tree-sitter + regex fallback), sends them to an LLM with anti-hallucination constraints, and outputs clean Markdown, HTML, or JSON documentation.
5
+ ```bash
6
+ npx legacyver analyze ./src
7
+ ```
8
+
9
+ No documentation written beforehand. No configuration required. One command.
10
+
11
+ ---
6
12
 
7
13
  ## Install
8
14
 
@@ -10,144 +16,183 @@ Legacyver crawls your source code, extracts structural facts with AST parsers (T
10
16
  npm install -g legacyver
11
17
  ```
12
18
 
13
- Requires Node.js >= 18.0.0.
19
+ Or use without installing:
20
+
21
+ ```bash
22
+ npx legacyver analyze ./src
23
+ ```
24
+
25
+ ---
14
26
 
15
27
  ## Quick Start
16
28
 
29
+ **1. Initialize (saves your API key):**
30
+
17
31
  ```bash
18
- # 1. Run the setup wizard
19
32
  legacyver init
33
+ ```
20
34
 
21
- # 2. Generate documentation
22
- legacyver analyze ./src
35
+ **2. Analyze a codebase:**
23
36
 
24
- # 3. View output
25
- open legacyver-docs/index.md
37
+ ```bash
38
+ legacyver analyze ./src
26
39
  ```
27
40
 
28
- ### Using Ollama (Free, Local)
29
-
30
- No API key required — just have [Ollama](https://ollama.ai) running:
41
+ **3. View the output:**
31
42
 
32
- ```bash
33
- legacyver analyze ./src --provider ollama
43
+ ```
44
+ legacyver-docs/
45
+ index.md ← project overview + dependency graph + route map (Laravel)
46
+ SUMMARY.md ← GitBook/Docusaurus compatible table of contents
47
+ src/
48
+ app.md
49
+ routes/users.md
50
+ ...
34
51
  ```
35
52
 
36
- ## CLI Reference
53
+ ---
37
54
 
38
- ### `legacyver analyze <path>`
55
+ ## CLI Commands
39
56
 
40
- Main command. Analyzes a codebase and generates documentation.
57
+ ### `legacyver analyze <dir>`
41
58
 
42
- | Flag | Description | Default |
43
- |---|---|---|
44
- | `-p, --provider <name>` | LLM provider (`anthropic`, `openai`, `google`, `groq`, `ollama`) | `anthropic` |
45
- | `-m, --model <name>` | Model name (overrides provider default) | Provider default |
46
- | `-o, --output <dir>` | Output directory | `./legacyver-docs` |
47
- | `-f, --format <type>` | Output format: `markdown`, `html`, `json` | `markdown` |
48
- | `-c, --concurrency <n>` | Concurrent LLM requests | `5` |
49
- | `--max-file-size <kb>` | Skip files larger than this (KB) | `500` |
50
- | `--incremental` | Only re-analyze changed files | `false` |
51
- | `--no-confirm` | Skip cost confirmation prompt | `false` |
52
- | `--dry-run` | Show cost estimate, no LLM calls | `false` |
53
- | `--ignore <patterns...>` | Additional glob patterns to ignore | `[]` |
54
- | `--json-summary` | Output JSON summary to stdout | `false` |
55
- | `--verbose` | Enable debug output | `false` |
59
+ Run the full documentation pipeline.
60
+
61
+ | Flag | Default | Description |
62
+ |------|---------|-------------|
63
+ | `--out <dir>` | `./legacyver-docs` | Output directory |
64
+ | `--format <fmt>` | `markdown` | Output format: `markdown`, `html`, `json` |
65
+ | `--provider <p>` | `openrouter` | LLM provider: `openrouter`, `ollama` |
66
+ | `--model <id>` | `meta-llama/llama-3.3-70b-instruct:free` | Model ID |
67
+ | `--incremental` | `false` | Skip files unchanged since last run |
68
+ | `--dry-run` | `false` | Estimate cost without calling LLM |
69
+ | `--concurrency <n>` | `3` | Max parallel LLM requests |
70
+ | `--max-file-size <kb>` | `500` | Skip files larger than this |
71
+ | `--no-confirm` | | Skip cost confirmation prompt |
72
+ | `--verbose` | `false` | Enable debug logging |
56
73
 
57
74
  ### `legacyver init`
58
75
 
59
- Interactive setup wizard. Configures your preferred LLM provider, saves API keys to OS user config, and creates a `.legacyverrc` file.
76
+ Interactive wizard. Detects existing `.legacyverrc` and warns before overwriting. Saves API key to OS user config.
60
77
 
61
78
  ### `legacyver providers`
62
79
 
63
- Lists all supported providers with API key status and pricing.
80
+ List all supported providers, API key status, and per-model pricing.
64
81
 
65
82
  ### `legacyver cache clear`
66
83
 
67
- Deletes the `.legacyver-cache/` directory.
84
+ Delete the `.legacyver-cache/` directory to force full re-analysis on next run.
85
+
86
+ ### `legacyver --version`
68
87
 
69
- ## Configuration
88
+ Print the installed version.
70
89
 
71
- Legacyver uses [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig) for configuration. It searches for:
90
+ ---
72
91
 
73
- - `.legacyverrc` (JSON)
74
- - `.legacyverrc.json`
75
- - `.legacyverrc.yaml`
76
- - `legacyver.config.js`
77
- - `legacyver.config.mjs`
92
+ ## `.legacyverrc` Schema
78
93
 
79
- ### `.legacyverrc` Schema
94
+ Create a `.legacyverrc` (JSON or YAML) in your project root:
80
95
 
81
96
  ```json
82
97
  {
83
- "provider": "anthropic",
84
- "model": null,
98
+ "provider": "openrouter",
99
+ "model": "meta-llama/llama-3.3-70b-instruct:free",
85
100
  "format": "markdown",
86
- "output": "./legacyver-docs",
87
- "concurrency": 5,
101
+ "out": "./legacyver-docs",
102
+ "concurrency": 3,
88
103
  "maxFileSizeKb": 500,
89
- "incremental": false,
90
- "ignore": ["test/**", "**/*.test.*"],
91
- "languages": ["javascript", "typescript", "python", "java", "go"]
104
+ "incremental": true
92
105
  }
93
106
  ```
94
107
 
95
- CLI flags always take precedence over config file values.
108
+ All fields are optional. CLI flags override file config.
109
+
110
+ Also supported: `legacyver.config.js`, `legacyver.config.yaml`.
111
+
112
+ ---
96
113
 
97
114
  ## Supported Languages
98
115
 
99
- | Language | Extensions | Parser |
100
- |---|---|---|
101
- | JavaScript | `.js`, `.jsx`, `.mjs` | Tree-sitter (WASM) or regex fallback |
102
- | TypeScript | `.ts`, `.tsx` | Tree-sitter (WASM) or regex fallback |
103
- | Python | `.py` | Tree-sitter (WASM) or regex fallback |
104
- | Java | `.java` | Tree-sitter (WASM) or regex fallback |
105
- | Go | `.go` | Tree-sitter (WASM) or regex fallback |
116
+ | Language | Extensions | Framework Support |
117
+ |----------|-----------|-------------------|
118
+ | JavaScript | `.js`, `.jsx`, `.mjs` | Express (auto-detected) |
119
+ | TypeScript | `.ts`, `.tsx` | |
120
+ | Python | `.py` | |
121
+ | Java | `.java` | |
122
+ | Go | `.go` | |
123
+ | PHP | `.php`, `.blade.php` | Laravel (auto-detected) |
106
124
 
107
- When Tree-sitter WASM grammars are not available, legacyver automatically falls back to a generic regex-based parser that extracts function signatures, class definitions, and imports.
125
+ **Laravel extras:** When an `artisan` file is detected, Legacyver automatically extracts:
126
+ - Route Map (Method, URI, Controller, Middleware, Route Name)
127
+ - Model Relationships (as Mermaid `erDiagram`)
128
+ - Service Provider Bindings
108
129
 
109
- ## Supported LLM Providers
130
+ ---
110
131
 
111
- | Provider | Default Model | Input Cost/1k tokens | Output Cost/1k tokens | API Key Env Var |
112
- |---|---|---|---|---|
113
- | Anthropic | `claude-haiku-3-5` | $0.00025 | $0.00125 | `ANTHROPIC_API_KEY` |
114
- | OpenAI | `gpt-4o-mini` | $0.00015 | $0.00060 | `OPENAI_API_KEY` |
115
- | Google | `gemini-1.5-flash` | $0.000075 | $0.00030 | `GOOGLE_API_KEY` |
116
- | Groq | `llama-3.1-70b-versatile` | $0.00059 | $0.00079 | `GROQ_API_KEY` |
117
- | Ollama | `llama3.2` | Free | Free | None (local) |
132
+ ## Supported LLM Providers
118
133
 
119
- ## Ignore Rules
134
+ | Provider | Env Var | Notes |
135
+ |----------|---------|-------|
136
+ | OpenRouter | `OPENROUTER_API_KEY` | Default. Free models available (`:free` suffix). Get a key at [openrouter.ai/keys](https://openrouter.ai/keys) |
137
+ | Ollama | — | Local/offline. Requires Ollama running: `ollama serve` |
120
138
 
121
- Legacyver respects a `.legacyverignore` file (same syntax as `.gitignore`) in your project root.
139
+ **Free usage:** The default model `meta-llama/llama-3.3-70b-instruct:free` is free via OpenRouter (rate-limited). Legacyver automatically caps concurrency to 1 for free models.
122
140
 
123
- Default ignores include: `node_modules`, `.git`, `dist`, `build`, `__pycache__`, `venv`, `vendor`, minified files, lock files, and more.
141
+ ---
124
142
 
125
- ## CI/CD Integration
143
+ ## Ignore Files
126
144
 
127
- Legacyver auto-detects non-interactive environments (no TTY) and disables spinners/prompts. For CI pipelines:
145
+ Create a `.legacyverignore` in your project root using gitignore syntax:
128
146
 
129
- ```bash
130
- legacyver analyze ./src --provider openai --no-confirm --json-summary
147
+ ```
148
+ # .legacyverignore
149
+ dist/
150
+ build/
151
+ coverage/
152
+ *.min.js
131
153
  ```
132
154
 
133
- The `--json-summary` flag outputs a machine-readable summary to stdout. The `--no-confirm` flag is required in non-interactive mode (otherwise legacyver exits with code 4).
155
+ See `.legacyverignore.example` for a documented example.
134
156
 
135
- ### Incremental Builds
157
+ ---
136
158
 
137
- Use `--incremental` to skip unchanged files between CI runs:
159
+ ## CI/CD Integration
138
160
 
139
- ```bash
140
- legacyver analyze ./src --incremental --no-confirm
161
+ ```yaml
162
+ # GitHub Actions example
163
+ - name: Generate docs
164
+ env:
165
+ OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
166
+ run: |
167
+ npx legacyver analyze ./src --no-confirm --incremental --out ./docs
141
168
  ```
142
169
 
143
- Cache is stored in `.legacyver-cache/` (auto-added to `.gitignore`).
170
+ Legacyver detects non-TTY environments and disables spinners/progress bars automatically (plain log output only).
171
+
172
+ ---
144
173
 
145
174
  ## How It Works
146
175
 
147
- 1. **Crawler** discovers source files using fast-glob, respecting ignore rules
148
- 2. **AST Parser** extracts structural facts (functions, classes, imports, exports, call graph) using Tree-sitter or regex fallback
149
- 3. **LLM Engine** sends facts + source code to the LLM with anti-hallucination constraints the LLM can only describe what's actually in the code
150
- 4. **Renderer** assembles the output as Markdown (with Mermaid diagrams), self-contained HTML (with search), or structured JSON
176
+ 1. **Crawl** `fast-glob` walks the directory, respects `.legacyverignore`
177
+ 2. **Parse** — Regex/heuristic AST extracts facts: function names, params, complexity scores, imports, exports, call patterns
178
+ 3. **PKG** — Assembles a Project Knowledge Graph linking all facts
179
+ 4. **LLM** Sends grounded facts + raw source to LLM; system prompt enforces anti-hallucination contract
180
+ 5. **Validate** — Post-generation checks: hallucination detection, completeness check (all exports documented)
181
+ 6. **Render** — Writes Markdown/HTML/JSON to output directory
182
+
183
+ **Design principle:** The LLM is a _writer_, not an analyst. AST extracts facts; LLM only explains them.
184
+
185
+ ---
186
+
187
+ ## Contributing
188
+
189
+ ```bash
190
+ git clone https://github.com/user/legacyver
191
+ npm install
192
+ npx vitest run
193
+ ```
194
+
195
+ ---
151
196
 
152
197
  ## License
153
198
 
package/bin/legacyver.js CHANGED
@@ -1,33 +1,56 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
- import { createRequire } from 'node:module';
4
- import { Command } from 'commander';
5
- import { registerAnalyzeCommand } from '../src/cli/commands/analyze.js';
6
- import { registerInitCommand } from '../src/cli/commands/init.js';
7
- import { registerProvidersCommand } from '../src/cli/commands/providers.js';
8
- import { registerCacheCommand } from '../src/cli/commands/cache.js';
9
- import { setVerbose } from '../src/utils/logger.js';
4
+ const { program } = require('commander');
5
+ const { readFileSync } = require('fs');
6
+ const { join } = require('path');
10
7
 
11
- const require = createRequire(import.meta.url);
12
- const pkg = require('../package.json');
13
-
14
- const program = new Command();
8
+ const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
15
9
 
16
10
  program
17
11
  .name('legacyver')
18
- .description('Generate technical documentation from undocumented or legacy codebases')
19
- .version(pkg.version)
20
- .option('--verbose', 'Enable verbose debug output', false)
21
- .hook('preAction', (thisCommand) => {
22
- const opts = thisCommand.opts();
23
- if (opts.verbose) {
24
- setVerbose(true);
25
- }
26
- });
27
-
28
- registerAnalyzeCommand(program);
29
- registerInitCommand(program);
30
- registerProvidersCommand(program);
31
- registerCacheCommand(program);
12
+ .description('AI-powered CLI tool to auto-generate technical documentation from legacy/undocumented codebases')
13
+ .version(pkg.version, '-v, --version', 'Output the current version')
14
+ .option('--verbose', 'Enable verbose debug logging');
15
+
16
+ // analyze command
17
+ const analyzeCmd = require('../src/cli/commands/analyze');
18
+ program
19
+ .command('analyze [target]')
20
+ .description('Analyze a directory and generate documentation')
21
+ .option('--out <dir>', 'Output directory', './legacyver-docs')
22
+ .option('--format <fmt>', 'Output format: markdown | html | json', 'markdown')
23
+ .option('--model <model>', 'LLM model to use')
24
+ .option('--provider <provider>', 'LLM provider: openrouter | ollama', 'openrouter')
25
+ .option('--concurrency <n>', 'Concurrent LLM requests (1-10)', '3')
26
+ .option('--dry-run', 'Run AST parsing only, no LLM calls')
27
+ .option('--incremental', 'Only re-analyze changed files')
28
+ .option('--no-confirm', 'Skip cost confirmation prompt')
29
+ .option('--json-summary', 'Output machine-readable JSON summary')
30
+ .option('--max-file-size <kb>', 'Skip files larger than this size in KB', '500')
31
+ .action(analyzeCmd);
32
+
33
+ // init command
34
+ const initCmd = require('../src/cli/commands/init');
35
+ program
36
+ .command('init')
37
+ .description('Interactive setup wizard — saves API key and creates .legacyverrc')
38
+ .action(initCmd);
39
+
40
+ // providers command
41
+ const providersCmd = require('../src/cli/commands/providers');
42
+ program
43
+ .command('providers')
44
+ .description('List supported LLM providers and available models')
45
+ .action(providersCmd);
46
+
47
+ // cache command
48
+ const cacheCmd = require('../src/cli/commands/cache');
49
+ program
50
+ .command('cache')
51
+ .description('Manage the incremental analysis cache')
52
+ .command('clear')
53
+ .description('Delete the .legacyver-cache/ directory')
54
+ .action(cacheCmd);
32
55
 
33
56
  program.parse(process.argv);
@@ -0,0 +1,3 @@
1
+ # Summary
2
+
3
+ * [components.tsx](components.md)
@@ -0,0 +1,57 @@
1
+ ## Overview
2
+ This file contains React components and a utility function for formatting currency amounts.
3
+
4
+ ## Functions
5
+
6
+ ### formatCurrency
7
+
8
+ #### Description
9
+ Formats a given amount as a string in a specified currency.
10
+
11
+ #### Params Table
12
+
13
+ | Name | Type |
14
+ | --- | --- |
15
+ | `amount` | `number` |
16
+ | `currency` | `string`, defaults to `'USD'` |
17
+
18
+ #### Return Value
19
+ A formatted string representing the currency amount.
20
+
21
+ ```typescript
22
+ export function formatCurrency(amount: number, currency: string = 'USD'): string {
23
+ return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount);
24
+ }
25
+ ```
26
+
27
+ ## Dependencies
28
+
29
+ * `react`
30
+ * `intl`
31
+
32
+ ## Overview
33
+ This file appears to contain UI components, with buttons and cards used for user representation.
34
+
35
+ ## Functions
36
+
37
+ ### Button
38
+ #### Description
39
+ A button component that can trigger an action.
40
+ #### Params Table
41
+ | Param | Type | Required |
42
+ | --- | --- | --- |
43
+ | - | - | No |
44
+ #### Return Value
45
+ N/A
46
+
47
+ ### UserCard
48
+ #### Description
49
+ A card component representing a user.
50
+ #### Params Table
51
+ | Param | Type | Required |
52
+ | --- | --- | --- |
53
+ | - | - | Yes |
54
+
55
+ ## Dependencies
56
+ * `@ui-component/library` (UI components library)
57
+ * `@utils/typography` (Typography utilities)
@@ -0,0 +1,15 @@
1
+ # src — Documentation
2
+
3
+ **Primary language:** typescript
4
+ **Total files:** 1
5
+ **Analyzed at:** 2026-02-21T07:52:12.371Z
6
+
7
+ ## Files
8
+
9
+ - [components.tsx](components.md)
10
+
11
+ ## Dependency Graph
12
+
13
+ ```mermaid
14
+ graph TD
15
+ ```
package/nul ADDED
@@ -0,0 +1,2 @@
1
+ dir: cannot access '/b': No such file or directory
2
+ dir: cannot access '/s': No such file or directory