legacyver 3.1.0 → 3.4.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.
Files changed (74) hide show
  1. package/bin/legacyver.js +1 -1
  2. package/legacyver-docs/auth.md +71 -0
  3. package/legacyver-docs/hash.md +37 -0
  4. package/package.json +3 -2
  5. package/src/api/auth.js +32 -45
  6. package/src/cli/commands/analyze.js +20 -1
  7. package/src/cli/commands/init.js +34 -4
  8. package/src/cli/commands/login.js +1 -1
  9. package/src/cli/commands/providers.js +20 -23
  10. package/src/cli/ui.js +19 -9
  11. package/src/db/config.js +39 -14
  12. package/src/db/index.js +69 -88
  13. package/src/llm/providers/groq.js +4 -2
  14. package/src/llm/validator.js +2 -2
  15. package/src/utils/config.js +1 -1
  16. package/legacyver-docs/bin/legacyver.md +0 -107
  17. package/legacyver-docs/src/api/auth.md +0 -47
  18. package/legacyver-docs/src/cache/hash.md +0 -24
  19. package/legacyver-docs/src/cache/index.md +0 -112
  20. package/legacyver-docs/src/cli/commands/analyze.md +0 -58
  21. package/legacyver-docs/src/cli/commands/cache.md +0 -21
  22. package/legacyver-docs/src/cli/commands/init.md +0 -42
  23. package/legacyver-docs/src/cli/commands/login.md +0 -70
  24. package/legacyver-docs/src/cli/commands/logout.md +0 -26
  25. package/legacyver-docs/src/cli/commands/providers.md +0 -23
  26. package/legacyver-docs/src/cli/commands/push.md +0 -48
  27. package/legacyver-docs/src/cli/commands/version.md +0 -26
  28. package/legacyver-docs/src/cli/ui.md +0 -112
  29. package/legacyver-docs/src/crawler/filters.md +0 -54
  30. package/legacyver-docs/src/crawler/index.md +0 -54
  31. package/legacyver-docs/src/crawler/manifest.md +0 -22
  32. package/legacyver-docs/src/crawler/walk.md +0 -29
  33. package/legacyver-docs/src/db/config.md +0 -13
  34. package/legacyver-docs/src/db/index.md +0 -86
  35. package/legacyver-docs/src/llm/chunker.md +0 -28
  36. package/legacyver-docs/src/llm/cost-estimator.md +0 -62
  37. package/legacyver-docs/src/llm/free-model.md +0 -40
  38. package/legacyver-docs/src/llm/index.md +0 -29
  39. package/legacyver-docs/src/llm/prompts.md +0 -150
  40. package/legacyver-docs/src/llm/providers/gemini.md +0 -51
  41. package/legacyver-docs/src/llm/providers/groq.md +0 -76
  42. package/legacyver-docs/src/llm/providers/kimi.md +0 -48
  43. package/legacyver-docs/src/llm/providers/ollama.md +0 -50
  44. package/legacyver-docs/src/llm/providers/openrouter.md +0 -55
  45. package/legacyver-docs/src/llm/queue.md +0 -41
  46. package/legacyver-docs/src/llm/re-prompter.md +0 -33
  47. package/legacyver-docs/src/llm/validator.md +0 -34
  48. package/legacyver-docs/src/parser/ast/generic.md +0 -34
  49. package/legacyver-docs/src/parser/ast/go.md +0 -59
  50. package/legacyver-docs/src/parser/ast/java.md +0 -58
  51. package/legacyver-docs/src/parser/ast/javascript.md +0 -71
  52. package/legacyver-docs/src/parser/ast/laravel/blade.md +0 -45
  53. package/legacyver-docs/src/parser/ast/laravel/classifier.md +0 -29
  54. package/legacyver-docs/src/parser/ast/laravel/controller.md +0 -57
  55. package/legacyver-docs/src/parser/ast/laravel/index.md +0 -27
  56. package/legacyver-docs/src/parser/ast/laravel/model.md +0 -34
  57. package/legacyver-docs/src/parser/ast/laravel/provider.md +0 -31
  58. package/legacyver-docs/src/parser/ast/laravel/routes.md +0 -31
  59. package/legacyver-docs/src/parser/ast/php.md +0 -127
  60. package/legacyver-docs/src/parser/ast/python.md +0 -62
  61. package/legacyver-docs/src/parser/ast/typescript.md +0 -22
  62. package/legacyver-docs/src/parser/body-extractor.md +0 -34
  63. package/legacyver-docs/src/parser/call-graph.md +0 -45
  64. package/legacyver-docs/src/parser/complexity-scorer.md +0 -25
  65. package/legacyver-docs/src/parser/index.md +0 -59
  66. package/legacyver-docs/src/parser/pattern-detector.md +0 -28
  67. package/legacyver-docs/src/parser/pkg-builder.md +0 -34
  68. package/legacyver-docs/src/renderer/html.md +0 -36
  69. package/legacyver-docs/src/renderer/index.md +0 -26
  70. package/legacyver-docs/src/renderer/json.md +0 -25
  71. package/legacyver-docs/src/renderer/markdown.md +0 -77
  72. package/legacyver-docs/src/utils/config.md +0 -62
  73. package/legacyver-docs/src/utils/errors.md +0 -53
  74. package/legacyver-docs/src/utils/logger.md +0 -48
package/src/db/index.js CHANGED
@@ -1,114 +1,103 @@
1
1
  'use strict';
2
2
 
3
- const { Pool } = require('pg');
4
3
  const path = require('path');
5
- const dbConfig = require('./config');
4
+ const { createDbClient } = require('./config');
6
5
  const { loadSession } = require('../utils/config');
7
6
  const { validateToken } = require('../api/auth');
8
7
  const logger = require('../utils/logger');
9
8
 
10
- let _pool = null;
11
-
12
- /**
13
- * Lazy singleton pool — created on first use, ended after push.
14
- */
15
- function getPool() {
16
- if (!_pool) {
17
- _pool = new Pool(dbConfig);
18
- }
19
- return _pool;
20
- }
21
-
22
9
  /**
23
10
  * Find or create a repository for the given user + project path.
24
- * @param {Pool} pool
25
11
  * @param {string} userId app.users.id (BIGINT as string)
26
12
  * @param {string} projectPath absolute path of the analyzed directory
27
13
  * @returns {Promise<string>} repository id (UUID)
28
14
  */
29
- async function getOrCreateRepo(pool, userId, projectPath) {
15
+ async function getOrCreateRepo(supabase, userId, projectPath) {
30
16
  const name = path.basename(projectPath);
31
17
  const fullName = projectPath;
32
18
 
33
19
  // Try find existing
34
- const existing = await pool.query(
35
- 'SELECT id FROM app.repositories WHERE user_id = $1 AND full_name = $2',
36
- [userId, fullName]
37
- );
38
- if (existing.rows.length > 0) {
39
- return existing.rows[0].id;
40
- }
20
+ const { data: existing, error: findErr } = await supabase
21
+ .schema('public')
22
+ .from('repositories')
23
+ .select('id')
24
+ .eq('user_id', userId)
25
+ .eq('full_name', fullName)
26
+ .maybeSingle();
27
+
28
+ if (findErr) throw findErr;
29
+ if (existing) return existing.id;
41
30
 
42
31
  // Insert new
43
- const inserted = await pool.query(
44
- 'INSERT INTO app.repositories (user_id, name, full_name) VALUES ($1, $2, $3) RETURNING id',
45
- [userId, name, fullName]
46
- );
47
- return inserted.rows[0].id;
32
+ const { data: inserted, error: insertErr } = await supabase
33
+ .schema('public')
34
+ .from('repositories')
35
+ .insert({ user_id: userId, name, full_name: fullName })
36
+ .select('id')
37
+ .single();
38
+
39
+ if (insertErr) throw insertErr;
40
+ return inserted.id;
48
41
  }
49
42
 
50
43
  /**
51
44
  * Find or create a documentation record for a repository.
52
45
  * One documentation per repository (title = repo name).
53
- * @param {Pool} pool
54
46
  * @param {string} repositoryId UUID
55
47
  * @param {string} repoName
56
48
  * @returns {Promise<string>} documentation id (UUID)
57
49
  */
58
- async function getOrCreateDocumentation(pool, repositoryId, repoName) {
59
- const existing = await pool.query(
60
- 'SELECT id FROM app.documentations WHERE repository_id = $1',
61
- [repositoryId]
62
- );
63
- if (existing.rows.length > 0) {
64
- return existing.rows[0].id;
65
- }
50
+ async function getOrCreateDocumentation(supabase, repositoryId, repoName) {
51
+ const { data: existing, error: findErr } = await supabase
52
+ .schema('public')
53
+ .from('documentations')
54
+ .select('id')
55
+ .eq('repository_id', repositoryId)
56
+ .maybeSingle();
66
57
 
67
- const inserted = await pool.query(
68
- 'INSERT INTO app.documentations (repository_id, title, description) VALUES ($1, $2, $3) RETURNING id',
69
- [repositoryId, `${repoName} Documentation`, `Auto-generated documentation for ${repoName}`]
70
- );
71
- return inserted.rows[0].id;
58
+ if (findErr) throw findErr;
59
+ if (existing) return existing.id;
60
+
61
+ const { data: inserted, error: insertErr } = await supabase
62
+ .schema('public')
63
+ .from('documentations')
64
+ .insert({
65
+ repository_id: repositoryId,
66
+ title: `${repoName} Documentation`,
67
+ description: `Auto-generated documentation for ${repoName}`,
68
+ })
69
+ .select('id')
70
+ .single();
71
+
72
+ if (insertErr) throw insertErr;
73
+ return inserted.id;
72
74
  }
73
75
 
74
76
  /**
75
77
  * Upsert documentation pages.
76
78
  * Each fragment becomes a page; slug = file path, title = file name.
77
79
  * Uses (documentation_id, slug) as the logical unique key.
78
- * @param {Pool} pool
79
80
  * @param {string} documentationId UUID
80
81
  * @param {Array<{relativePath: string, content: string}>} fragments
81
82
  * @returns {Promise<number>} count of upserted pages
82
83
  */
83
- async function upsertPages(pool, documentationId, fragments) {
84
- let count = 0;
85
- for (let i = 0; i < fragments.length; i++) {
86
- const frag = fragments[i];
87
- const slug = frag.relativePath.replace(/\\/g, '/');
88
- const title = path.basename(frag.relativePath);
89
-
90
- // Check if page exists
91
- const existing = await pool.query(
92
- 'SELECT id FROM app.documentation_pages WHERE documentation_id = $1 AND slug = $2',
93
- [documentationId, slug]
94
- );
95
-
96
- if (existing.rows.length > 0) {
97
- // Update existing
98
- await pool.query(
99
- 'UPDATE app.documentation_pages SET content = $1, title = $2, page_order = $3, created_at = NOW() WHERE id = $4',
100
- [frag.content, title, i + 1, existing.rows[0].id]
101
- );
102
- } else {
103
- // Insert new
104
- await pool.query(
105
- 'INSERT INTO app.documentation_pages (documentation_id, slug, title, content, page_order) VALUES ($1, $2, $3, $4, $5)',
106
- [documentationId, slug, title, frag.content, i + 1]
107
- );
108
- }
109
- count++;
110
- }
111
- return count;
84
+ async function upsertPages(supabase, documentationId, fragments) {
85
+ const rows = fragments.map((frag, i) => ({
86
+ documentation_id: documentationId,
87
+ slug: frag.relativePath.replace(/\\/g, '/'),
88
+ title: path.basename(frag.relativePath),
89
+ content: frag.content,
90
+ page_order: i + 1,
91
+ created_at: new Date().toISOString(),
92
+ }));
93
+
94
+ const { error } = await supabase
95
+ .schema('public')
96
+ .from('documentation_pages')
97
+ .upsert(rows, { onConflict: 'documentation_id,slug' });
98
+
99
+ if (error) throw error;
100
+ return rows.length;
112
101
  }
113
102
 
114
103
  /**
@@ -118,7 +107,6 @@ async function upsertPages(pool, documentationId, fragments) {
118
107
  * @param {Array<{relativePath: string, content: string}>} fragments
119
108
  * @param {string} projectPath absolute path of the analyzed directory
120
109
  * @param {object} [opts] optional overrides for testing
121
- * @param {object} [opts.pool] pg Pool instance (skips singleton pool)
122
110
  * @param {object} [opts.session] session object (skips loadSession)
123
111
  * @param {object} [opts.user] user object (skips validateToken) — { userId, username, email }
124
112
  * @returns {Promise<{skipped: boolean, pushed?: number}>}
@@ -138,20 +126,13 @@ async function pushToDatabase(fragments, projectPath, opts) {
138
126
  }
139
127
  }
140
128
 
141
- const ownPool = !(opts && opts.pool);
142
- const pool = (opts && opts.pool) || getPool();
143
- try {
144
- const repoName = path.basename(projectPath);
145
- const repoId = await getOrCreateRepo(pool, user.userId, projectPath);
146
- const docId = await getOrCreateDocumentation(pool, repoId, repoName);
147
- const pushed = await upsertPages(pool, docId, fragments);
148
- return { skipped: false, pushed };
149
- } finally {
150
- if (ownPool) {
151
- await pool.end().catch(() => {});
152
- _pool = null;
153
- }
154
- }
129
+ const supabase = createDbClient(session.token);
130
+
131
+ const repoName = path.basename(projectPath);
132
+ const repoId = await getOrCreateRepo(supabase, user.userId, projectPath);
133
+ const docId = await getOrCreateDocumentation(supabase, repoId, repoName);
134
+ const pushed = await upsertPages(supabase, docId, fragments);
135
+ return { skipped: false, pushed };
155
136
  }
156
137
 
157
- module.exports = { getPool, getOrCreateRepo, getOrCreateDocumentation, upsertPages, pushToDatabase };
138
+ module.exports = { getOrCreateRepo, getOrCreateDocumentation, upsertPages, pushToDatabase };
@@ -3,10 +3,12 @@
3
3
  const { NoApiKeyError } = require('../../utils/errors');
4
4
 
5
5
  const GROQ_BASE = 'https://api.groq.com/openai/v1';
6
- const DEFAULT_MODEL = 'llama-3.3-70b-versatile';
6
+ const DEFAULT_MODEL = 'openai/gpt-oss-120b';
7
7
  // Built-in shared key — lets users run legacyver out of the box without setup.
8
8
  // Users can override with their own GROQ_API_KEY env var for higher rate limits.
9
- const BUILT_IN_KEY = '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';
9
+ // Groq does NOT auto-revoke keys found in public packages (unlike OpenRouter).
10
+ const BUILT_IN_KEY = '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';
11
+
10
12
  class GroqProvider {
11
13
  constructor(config) {
12
14
  this.apiKey = process.env.GROQ_API_KEY || config.groqApiKey || BUILT_IN_KEY;
@@ -46,8 +46,8 @@ function validateFragment(fragment, fileFacts) {
46
46
  'Parameter', 'Parameters', 'Param', 'Import', 'Export', 'Overview', 'Usage', 'Example',
47
47
  'Dependencies', 'Dependency', 'Async', 'Static', 'Public', 'Private', 'Protected',
48
48
  'Boolean', 'String', 'Number', 'Object', 'Array', 'Void', 'Null', 'Undefined',
49
- 'True', 'False', 'Error', 'Promise', 'Request', 'Response',
50
- 'Node', 'JavaScript', 'TypeScript', 'PHP', 'Python',
49
+ 'True', 'False', 'Error', 'Promise', 'Request', 'Response',
50
+ 'Node', 'JavaScript', 'TypeScript', 'PHP', 'Python', 'PostgreSQL',
51
51
  'Laravel', 'Express', 'Route', 'Controller', 'Model', 'Service', 'Repository',
52
52
  'Middleware', 'Provider', 'Summary', 'None', 'Name', 'Description', 'Value', 'Type',
53
53
  'Map', 'Set', 'Date',
@@ -59,7 +59,7 @@ function loadConfig(cliFlags = {}) {
59
59
  }
60
60
 
61
61
  const defaults = {
62
- provider: 'openrouter',
62
+ provider: 'groq',
63
63
  model: undefined,
64
64
  format: 'markdown',
65
65
  out: './legacyver-docs',
@@ -1,107 +0,0 @@
1
- ## Overview
2
- The `legacyver` CLI tool is an AI-powered tool for auto-generating technical documentation from legacy/undocumented codebases. It provides various commands for analysis, initialization, provider management, caching, login, logout, and pushing documentation to the cloud.
3
-
4
- ## Functions
5
- ### `analyzeCmd`
6
- #### Description
7
- Analyze a directory and generate documentation.
8
-
9
- #### Parameters
10
- | Name | Type | Description |
11
- | --- | --- | --- |
12
- | `target` | string | The directory to analyze. |
13
- | `--out <dir>` | string | Output directory (default: `./legacyver-docs`). |
14
- | `--format <fmt>` | string | Output format: `markdown`, `html`, or `json` (default: `markdown`). |
15
- | `--model <model>` | string | LLM model to use. |
16
- | `--provider <provider>` | string | LLM provider: `groq` or `ollama` (default: `groq`). |
17
- | `--concurrency <n>` | number | Concurrent LLM requests (1-10) (default: `3`). |
18
- | `--dry-run` | boolean | Run AST parsing only, no LLM calls. |
19
- | `--incremental` | boolean | Only re-analyze changed files. |
20
- | `--no-confirm` | boolean | Skip cost confirmation prompt. |
21
- | `--json-summary` | boolean | Output machine-readable JSON summary. |
22
- | `--max-file-size <kb>` | number | Skip files larger than this size in KB (default: `500`). |
23
-
24
- #### Return Value
25
- None
26
-
27
- ### `initCmd`
28
- #### Description
29
- Interactive setup wizard — saves API key and creates `.legacyverrc`.
30
-
31
- #### Parameters
32
- None
33
-
34
- #### Return Value
35
- None
36
-
37
- ### `providersCmd`
38
- #### Description
39
- List supported LLM providers and available models.
40
-
41
- #### Parameters
42
- None
43
-
44
- #### Return Value
45
- None
46
-
47
- ### `cacheCmd`
48
- #### Description
49
- Manage the incremental analysis cache.
50
-
51
- #### Parameters
52
- None
53
-
54
- #### Return Value
55
- None
56
-
57
- ### `loginCmd`
58
- #### Description
59
- Log in to sync generated docs to the cloud.
60
-
61
- #### Parameters
62
- None
63
-
64
- #### Return Value
65
- None
66
-
67
- ### `logoutCmd`
68
- #### Description
69
- Log out and stop syncing docs to the cloud.
70
-
71
- #### Parameters
72
- None
73
-
74
- #### Return Value
75
- None
76
-
77
- ### `pushCmd`
78
- #### Description
79
- Manually push generated docs to the cloud database.
80
-
81
- #### Parameters
82
- | Name | Type | Description |
83
- | --- | --- | --- |
84
- | `target` | string | The directory to push from. |
85
- | `--out <dir>` | string | Docs output directory to read from (default: `./legacyver-docs`). |
86
-
87
- #### Return Value
88
- None
89
-
90
- ## Dependencies
91
- * `commander`
92
- * `fs`
93
- * `path`
94
- * `dotenv`
95
- * `../src/cli/commands/analyze`
96
- * `../src/cli/commands/init`
97
- * `../src/cli/commands/providers`
98
- * `../src/cli/commands/cache`
99
- * `../src/cli/commands/login`
100
- * `../src/cli/commands/logout`
101
- * `../src/cli/commands/push`
102
-
103
- ## Usage Example
104
- ```bash
105
- legacyver analyze my-project --out docs --format markdown
106
- ```
107
- This command analyzes the `my-project` directory, generates documentation in Markdown format, and outputs it to the `docs` directory.
@@ -1,47 +0,0 @@
1
- ## Overview
2
- This module provides two functions for managing CLI session tokens: `validateToken` and `revokeToken`. These functions interact with a PostgreSQL database to validate and revoke tokens.
3
-
4
- ## Functions
5
-
6
- ### validateToken
7
- Validates a CLI session token against app.user_sessions.
8
-
9
- * **Description**: Returns user info if valid, null if expired/revoked/not found.
10
- * **Params**:
11
- + `token`: raw token from ~/.legacyver/session.json (string)
12
- + `opts`: optional overrides for testing (object)
13
- - `pool`: pg Pool instance (object)
14
- * **Return Value**: Promise<{userId: string, username: string, email: string} | null>
15
-
16
- ### revokeToken
17
- Revoke a CLI session token (logout).
18
-
19
- * **Description**: Revoke a CLI session token.
20
- * **Params**:
21
- + `token`: raw token (string)
22
- + `opts`: optional overrides for testing (object)
23
- - `pool`: pg Pool instance (object)
24
- * **Return Value**: None
25
-
26
- ## Dependencies
27
- * `crypto`: crypto module
28
- * `pg`: pg module
29
- * `../db/config`: dbConfig module
30
-
31
- ## Usage Example
32
- ```javascript
33
- const { validateToken, revokeToken } = require('./auth');
34
-
35
- // Validate a token
36
- const token = 'your_token_here';
37
- const opts = { pool: your_pool_instance };
38
- validateToken(token, opts).then((userInfo) => {
39
- console.log(userInfo);
40
- });
41
-
42
- // Revoke a token
43
- const token = 'your_token_here';
44
- revokeToken(token, opts).then(() => {
45
- console.log('Token revoked');
46
- });
47
- ```
@@ -1,24 +0,0 @@
1
- ## Overview
2
- This module provides a function to compute the SHA-256 hash of a file.
3
-
4
- ## Functions
5
- ### computeHash
6
- Computes the SHA-256 hash of a file.
7
-
8
- | Parameter | Type | Description |
9
- | --- | --- | --- |
10
- | filePath | string | Path to the file to compute the hash for |
11
-
12
- | Return Value | Type | Description |
13
- | --- | --- | --- |
14
- | string | The SHA-256 hash as a hex string prefixed with 'sha256:' |
15
-
16
- ## Dependencies
17
- * crypto: createHash
18
- * fs: readFileSync
19
-
20
- ## Usage Example
21
- ```javascript
22
- const { computeHash } = require('./hash');
23
- console.log(computeHash('path/to/file.txt'));
24
- ```
@@ -1,112 +0,0 @@
1
- ## Overview
2
- This module provides functions for managing a cache of file hashes in a `.legacyver-cache` directory. It includes functions for loading and saving the cache, separating files into cache hits and misses, removing entries for files that no longer exist on disk, and auto-adding the cache directory to `.gitignore`.
3
-
4
- ## Functions
5
-
6
- ### loadCache
7
- Load cache from `.legacyver-cache/hashes.json`.
8
-
9
- * **Params:**
10
- + `cacheDir`: string
11
- * **Returns:** Object
12
- + map of relativePath -> { hash, docFile, generatedAt }
13
-
14
- ```javascript
15
- function loadCache(cacheDir) {
16
- const cachePath = path.join(cacheDir, CACHE_FILE);
17
- if (!existsSync(cachePath)) return {};
18
- try {
19
- return JSON.parse(readFileSync(cachePath, 'utf8'));
20
- } catch (e) {
21
- logger.warn(`Could not read cache: ${e.message}`);
22
- return {};
23
- }
24
- }
25
- ```
26
-
27
- ### saveCache
28
- Save cache to `.legacyver-cache/hashes.json`.
29
-
30
- * **Params:**
31
- + `cacheDir`: string
32
- + `map`: Object
33
- * **Returns:** None
34
-
35
- ```javascript
36
- function saveCache(cacheDir, map) {
37
- mkdirSync(cacheDir, { recursive: true });
38
- const cachePath = path.join(cacheDir, CACHE_FILE);
39
- writeFileSync(cachePath, JSON.stringify(map, null, 2), 'utf8');
40
- }
41
- ```
42
-
43
- ### getCacheHits
44
- Separate files into cache hits and misses.
45
-
46
- * **Params:**
47
- + `manifest`: Array of FileManifest[]
48
- + `cacheMap`: Object
49
- * **Returns:** { hits: Array, misses: Array }
50
-
51
- ```javascript
52
- function getCacheHits(manifest, cacheMap) {
53
- const hits = [];
54
- const misses = [];
55
- for (const file of manifest) {
56
- const cached = cacheMap[file.relativePath];
57
- if (cached && cached.hash === file.hash) {
58
- hits.push(file);
59
- } else {
60
- misses.push(file);
61
- }
62
- }
63
- return { hits, misses };
64
- }
65
- ```
66
-
67
- ### purgeDeleted
68
- Remove entries for files that no longer exist on disk.
69
-
70
- * **Params:**
71
- + `cacheMap`: Object (mutated in place)
72
- + `currentPaths`: string[]
73
-
74
- ```javascript
75
- function purgeDeleted(cacheMap, currentPaths) {
76
- const current = new Set(currentPaths);
77
- for (const key of Object.keys(cacheMap)) {
78
- if (!current.has(key)) {
79
- delete cacheMap[key];
80
- }
81
- }
82
- }
83
- ```
84
-
85
- ### autoAddToGitignore
86
- Auto-add `.legacyver-cache/` to `.gitignore` if it exists in `projectRoot`.
87
-
88
- * **Params:**
89
- + `projectRoot`: string
90
- * **Patterns:**
91
- + arithmetic (used for appending to `.gitignore`)
92
-
93
- ```javascript
94
- function autoAddToGitignore(projectRoot) {
95
- const gitignorePath = path.join(projectRoot, '.gitignore');
96
- if (!existsSync(gitignorePath)) return;
97
- const content = readFileSync(gitignorePath, 'utf8');
98
- if (!content.includes('.legacyver-cache')) {
99
- appendFileSync(gitignorePath, '\n.legacyver-cache/\n');
100
- logger.info('Added.legacyver-cache/ to.gitignore');
101
- }
102
- }
103
- ```
104
-
105
- ## Dependencies
106
-
107
- * `fs`: readFileSync, writeFileSync, mkdirSync, existsSync, appendFileSync
108
- * `path`: path
109
- * `../utils/logger`: logger
110
-
111
- ## Usage Example
112
- No clear pattern is visible in the code.
@@ -1,58 +0,0 @@
1
- ## Overview
2
- The `analyzeCommand` function is the main entry point for the `analyze` CLI command. It takes a `target` directory and `flags` object as input, and performs a series of tasks to analyze the files in the target directory.
3
-
4
- ## Functions
5
- ### analyzeCommand
6
- #### Description
7
- Analyzes the files in the target directory using a series of stages, including crawling, incremental caching, AST parsing, dry run estimation, free model policy application, cost gate checking, and LLM engine execution.
8
-
9
- #### Parameters
10
- | Name | Type | Description |
11
- | --- | --- | --- |
12
- | target | string | The target directory to analyze |
13
- | flags | object | The CLI flags object |
14
-
15
- #### Return Value
16
- No return value
17
-
18
- #### Dependencies
19
- * `loadConfig`
20
- * `crawl`
21
- * `parseFiles`
22
- * `estimateCost`
23
- * `applyFreeModelPolicy`
24
- * `createProvider`
25
- * `validateFragment`
26
- * `reprompt`
27
- * `createQueue`
28
- * `buildChunks`
29
-
30
- ## Dependencies
31
- * `path`
32
- * `loadConfig`
33
- * `createSpinner`
34
- * `createProgressBar`
35
- * `confirmPrompt`
36
- * `printSummary`
37
- * `logger`
38
- * `picocolors`
39
- * `NoApiKeyError`
40
- * `crawl`
41
- * `cache`
42
- * `parseFiles`
43
- * `estimateCost`
44
- * `buildChunks`
45
- * `applyFreeModelPolicy`
46
- * `createProvider`
47
- * `validateFragment`
48
- * `reprompt`
49
- * `createQueue`
50
- * `pushToDatabase`
51
- * `loadSession`
52
-
53
- ## Usage Example
54
- The `analyzeCommand` function can be used by running the `analyze` CLI command with the `--target` option followed by the target directory, and any desired flags. For example:
55
- ```bash
56
- legacyver analyze --target /path/to/directory --provider groq --model my-model
57
- ```
58
- This will perform the analysis on the files in the specified directory using the Groq provider and my-model model.
@@ -1,21 +0,0 @@
1
- ## Overview
2
- This module exports a single asynchronous function, `cacheClearCommand`, which clears the cache directory.
3
-
4
- ## Functions
5
- ### cacheClearCommand
6
- Clears the cache directory.
7
-
8
- | Parameter | Type | Description |
9
- | --- | --- | --- |
10
- | None | | |
11
-
12
- Return Value:
13
- No return value.
14
-
15
- ## Dependencies
16
- * `fs`: `existsSync`, `rmSync`
17
- * `path`: `join`
18
- * `picocolors`: `pc`
19
-
20
- ## Usage Example
21
- The function clears the cache directory located at `.legacyver-cache/` in the current working directory. If the directory exists, it is deleted recursively with force. If the directory does not exist, a message indicating that no cache directory was found is logged.
@@ -1,42 +0,0 @@
1
- ## Overview
2
- The `initCommand` function is the main entry point for the Legacyver setup wizard, responsible for guiding the user through the setup process and creating a configuration file.
3
-
4
- ## Functions
5
- ### ask
6
- #### Description
7
- Asks a question to the user and returns a promise that resolves with the user's response.
8
-
9
- #### Parameters
10
- | Name | Type | Description |
11
- | --- | --- | --- |
12
- | `rl` | `readline.Interface` | The readline interface to use for asking the question. |
13
- | `question` | `string` | The question to ask the user. |
14
-
15
- #### Return Value
16
- A promise that resolves with the user's response.
17
-
18
- ### initCommand
19
- #### Description
20
- The main entry point for the Legacyver setup wizard, responsible for guiding the user through the setup process and creating a configuration file.
21
-
22
- #### Parameters
23
- None
24
-
25
- #### Return Value
26
- None
27
-
28
- ## Dependencies
29
- * `fs`: `existsSync`, `writeFileSync`
30
- * `path`: `join`
31
- * `readline`: `readline.createInterface`
32
- * `picocolors`: `pc`
33
-
34
- ## Usage Example
35
- The `initCommand` function can be used as a standalone command to guide the user through the setup process and create a configuration file. For example:
36
- ```javascript
37
- const initCommand = require('./init');
38
- initCommand().then(() => {
39
- console.log('Setup complete!');
40
- });
41
- ```
42
- Note: This example assumes that the `initCommand` function is exported from the `init.js` file.