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.
- package/bin/legacyver.js +1 -1
- package/legacyver-docs/auth.md +71 -0
- package/legacyver-docs/hash.md +37 -0
- package/package.json +3 -2
- package/src/api/auth.js +32 -45
- package/src/cli/commands/analyze.js +20 -1
- package/src/cli/commands/init.js +34 -4
- package/src/cli/commands/login.js +1 -1
- package/src/cli/commands/providers.js +20 -23
- package/src/cli/ui.js +19 -9
- package/src/db/config.js +39 -14
- package/src/db/index.js +69 -88
- package/src/llm/providers/groq.js +4 -2
- package/src/llm/validator.js +2 -2
- package/src/utils/config.js +1 -1
- package/legacyver-docs/bin/legacyver.md +0 -107
- package/legacyver-docs/src/api/auth.md +0 -47
- package/legacyver-docs/src/cache/hash.md +0 -24
- package/legacyver-docs/src/cache/index.md +0 -112
- package/legacyver-docs/src/cli/commands/analyze.md +0 -58
- package/legacyver-docs/src/cli/commands/cache.md +0 -21
- package/legacyver-docs/src/cli/commands/init.md +0 -42
- package/legacyver-docs/src/cli/commands/login.md +0 -70
- package/legacyver-docs/src/cli/commands/logout.md +0 -26
- package/legacyver-docs/src/cli/commands/providers.md +0 -23
- package/legacyver-docs/src/cli/commands/push.md +0 -48
- package/legacyver-docs/src/cli/commands/version.md +0 -26
- package/legacyver-docs/src/cli/ui.md +0 -112
- package/legacyver-docs/src/crawler/filters.md +0 -54
- package/legacyver-docs/src/crawler/index.md +0 -54
- package/legacyver-docs/src/crawler/manifest.md +0 -22
- package/legacyver-docs/src/crawler/walk.md +0 -29
- package/legacyver-docs/src/db/config.md +0 -13
- package/legacyver-docs/src/db/index.md +0 -86
- package/legacyver-docs/src/llm/chunker.md +0 -28
- package/legacyver-docs/src/llm/cost-estimator.md +0 -62
- package/legacyver-docs/src/llm/free-model.md +0 -40
- package/legacyver-docs/src/llm/index.md +0 -29
- package/legacyver-docs/src/llm/prompts.md +0 -150
- package/legacyver-docs/src/llm/providers/gemini.md +0 -51
- package/legacyver-docs/src/llm/providers/groq.md +0 -76
- package/legacyver-docs/src/llm/providers/kimi.md +0 -48
- package/legacyver-docs/src/llm/providers/ollama.md +0 -50
- package/legacyver-docs/src/llm/providers/openrouter.md +0 -55
- package/legacyver-docs/src/llm/queue.md +0 -41
- package/legacyver-docs/src/llm/re-prompter.md +0 -33
- package/legacyver-docs/src/llm/validator.md +0 -34
- package/legacyver-docs/src/parser/ast/generic.md +0 -34
- package/legacyver-docs/src/parser/ast/go.md +0 -59
- package/legacyver-docs/src/parser/ast/java.md +0 -58
- package/legacyver-docs/src/parser/ast/javascript.md +0 -71
- package/legacyver-docs/src/parser/ast/laravel/blade.md +0 -45
- package/legacyver-docs/src/parser/ast/laravel/classifier.md +0 -29
- package/legacyver-docs/src/parser/ast/laravel/controller.md +0 -57
- package/legacyver-docs/src/parser/ast/laravel/index.md +0 -27
- package/legacyver-docs/src/parser/ast/laravel/model.md +0 -34
- package/legacyver-docs/src/parser/ast/laravel/provider.md +0 -31
- package/legacyver-docs/src/parser/ast/laravel/routes.md +0 -31
- package/legacyver-docs/src/parser/ast/php.md +0 -127
- package/legacyver-docs/src/parser/ast/python.md +0 -62
- package/legacyver-docs/src/parser/ast/typescript.md +0 -22
- package/legacyver-docs/src/parser/body-extractor.md +0 -34
- package/legacyver-docs/src/parser/call-graph.md +0 -45
- package/legacyver-docs/src/parser/complexity-scorer.md +0 -25
- package/legacyver-docs/src/parser/index.md +0 -59
- package/legacyver-docs/src/parser/pattern-detector.md +0 -28
- package/legacyver-docs/src/parser/pkg-builder.md +0 -34
- package/legacyver-docs/src/renderer/html.md +0 -36
- package/legacyver-docs/src/renderer/index.md +0 -26
- package/legacyver-docs/src/renderer/json.md +0 -25
- package/legacyver-docs/src/renderer/markdown.md +0 -77
- package/legacyver-docs/src/utils/config.md +0 -62
- package/legacyver-docs/src/utils/errors.md +0 -53
- package/legacyver-docs/src/utils/logger.md +0 -48
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
The `loginCommand` function is an asynchronous command that handles the login process for the Legacyver CLI. It opens a browser to log in with GitHub, waits for the web app to redirect the token back, and saves the session.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### openBrowser
|
|
6
|
-
Opens a URL in the default browser (cross-platform).
|
|
7
|
-
|
|
8
|
-
#### Parameters
|
|
9
|
-
| Name | Type | Description |
|
|
10
|
-
| --- | --- | --- |
|
|
11
|
-
| url | string | The URL to open in the browser |
|
|
12
|
-
|
|
13
|
-
#### Return Value
|
|
14
|
-
None
|
|
15
|
-
|
|
16
|
-
#### Body
|
|
17
|
-
```javascript
|
|
18
|
-
const { exec } = require('child_process');
|
|
19
|
-
const cmd = process.platform === 'win32' ? `start "" "${url}"`
|
|
20
|
-
: process.platform === 'darwin' ? `open "${url}"`
|
|
21
|
-
: `xdg-open "${url}"`;
|
|
22
|
-
exec(cmd);
|
|
23
|
-
```
|
|
24
|
-
This function uses the `child_process` module to execute a command to open the URL in the default browser. The command is platform-dependent, using `start` on Windows, `open` on macOS, and `xdg-open` on Linux.
|
|
25
|
-
|
|
26
|
-
### loginCommand
|
|
27
|
-
Spawns a temporary local HTTP server, opens the browser for GitHub OAuth, and waits for the web app to redirect the token back.
|
|
28
|
-
|
|
29
|
-
#### Parameters
|
|
30
|
-
None
|
|
31
|
-
|
|
32
|
-
#### Return Value
|
|
33
|
-
A Promise that resolves when the login is complete
|
|
34
|
-
|
|
35
|
-
#### Body
|
|
36
|
-
```javascript
|
|
37
|
-
const session = loadSession();
|
|
38
|
-
if (session.token) {
|
|
39
|
-
console.log(pc.yellow(`Already logged in as ${session.username} (${session.email}).`));
|
|
40
|
-
console.log(`Run ${pc.cyan('legacyver logout')} first to switch accounts.`);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
console.log(pc.bold('\nLegacyver Login\n'));
|
|
45
|
-
console.log(pc.dim('Opening your browser to log in with GitHub...\n'));
|
|
46
|
-
|
|
47
|
-
const code = crypto.randomBytes(16).toString('hex');
|
|
48
|
-
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
const server = http.createServer((req, res) => {
|
|
51
|
-
// ...
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// ...
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
This function first checks if the user is already logged in. If not, it generates a random code and starts a local HTTP server. It then opens the browser to the GitHub OAuth page with the code as a query parameter. When the user logs in with GitHub, the web app redirects the token back to the local server, which saves the session and shuts down the server.
|
|
58
|
-
|
|
59
|
-
## Dependencies
|
|
60
|
-
* `http`
|
|
61
|
-
* `crypto`
|
|
62
|
-
* `picocolors`
|
|
63
|
-
* `../../utils/config` (for `saveSession` and `loadSession`)
|
|
64
|
-
|
|
65
|
-
## Usage Example
|
|
66
|
-
To use the `loginCommand` function, simply call it as an asynchronous command:
|
|
67
|
-
```javascript
|
|
68
|
-
await loginCommand();
|
|
69
|
-
```
|
|
70
|
-
This will open the browser to log in with GitHub and wait for the web app to redirect the token back. Once the login is complete, the function will resolve and the CLI will continue running.
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This is a JavaScript module that exports a function `logoutCommand` which handles the logout process for a user. It checks if the user is logged in, revokes the token, and clears the local session.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### logoutCommand
|
|
6
|
-
#### Description
|
|
7
|
-
This function handles the logout process for a user.
|
|
8
|
-
|
|
9
|
-
#### Parameters
|
|
10
|
-
| Name | Type | Description |
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| None | | This function does not take any parameters. |
|
|
13
|
-
|
|
14
|
-
#### Return Value
|
|
15
|
-
None
|
|
16
|
-
|
|
17
|
-
#### Body
|
|
18
|
-
The function first loads the current session using `loadSession()`. If the session does not have a token, it logs a message indicating that the user is not logged in and returns. If the session has a token, it attempts to revoke the token using `revokeToken(session.token)`. If the token revocation fails, it catches the error and still clears the local session. Finally, it clears the session using `clearSession()` and logs a success message using `pc.green('Logged out.')`.
|
|
19
|
-
|
|
20
|
-
## Dependencies
|
|
21
|
-
* `picocolors` (as `pc`)
|
|
22
|
-
* `../../utils/config` (for `loadSession` and `clearSession`)
|
|
23
|
-
* `../../api/auth` (for `revokeToken`)
|
|
24
|
-
|
|
25
|
-
## Usage Example
|
|
26
|
-
No clear usage example is visible in the code.
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This is a command-line interface (CLI) function named `providersCommand` that displays information about supported LLM (Large Language Model) providers and their recommended models.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### providersCommand
|
|
6
|
-
#### Description
|
|
7
|
-
Displays information about supported LLM providers and their recommended models.
|
|
8
|
-
|
|
9
|
-
#### Parameters
|
|
10
|
-
| Name | Type | Description |
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| None | | This function does not take any parameters. |
|
|
13
|
-
|
|
14
|
-
#### Return Value
|
|
15
|
-
None
|
|
16
|
-
|
|
17
|
-
## Dependencies
|
|
18
|
-
* `picocolors` (as `pc`)
|
|
19
|
-
* `../../utils/logger` (as `logger`)
|
|
20
|
-
* `../../utils/config` (as `loadConfig` and `loadSession`)
|
|
21
|
-
|
|
22
|
-
## Usage Example
|
|
23
|
-
This function is designed to be called as a CLI command, and its output will display information about supported LLM providers and their recommended models. The exact output will depend on the environment variables set in the system, such as `GROQ_API_KEY`, `GEMINI_API_KEY`, `MOONSHOT_API_KEY`, and `OPENROUTER_API_KEY`.
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
The `pushCommand` function is a CLI command that manually pushes existing generated documentation to the cloud database. It reads markdown files from the output directory and pushes them as documentation pages.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### pushCommand
|
|
6
|
-
#### Description
|
|
7
|
-
Manually push existing generated docs to the cloud database.
|
|
8
|
-
|
|
9
|
-
#### Parameters
|
|
10
|
-
| Name | Type | Description |
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| target | string | The directory to read markdown files from (default: current directory) |
|
|
13
|
-
| options | object | Options object (contains `out` property) |
|
|
14
|
-
|
|
15
|
-
#### Return Value
|
|
16
|
-
No return value
|
|
17
|
-
|
|
18
|
-
#### Detected Patterns
|
|
19
|
-
* Arithmetic operations are used to calculate the number of markdown files found in the output directory.
|
|
20
|
-
|
|
21
|
-
### collectMarkdownFiles
|
|
22
|
-
#### Description
|
|
23
|
-
Recursively collect .md files from a directory. Each file becomes a fragment with { relativePath, content }.
|
|
24
|
-
|
|
25
|
-
#### Parameters
|
|
26
|
-
| Name | Type | Description |
|
|
27
|
-
| --- | --- | --- |
|
|
28
|
-
| baseDir | string | The base directory to resolve relative paths from |
|
|
29
|
-
| dir | string | The directory to read files from |
|
|
30
|
-
| results | array | The array to store the collected fragments |
|
|
31
|
-
|
|
32
|
-
#### Return Value
|
|
33
|
-
No return value
|
|
34
|
-
|
|
35
|
-
## Dependencies
|
|
36
|
-
* `path`
|
|
37
|
-
* `fs`
|
|
38
|
-
* `picocolors`
|
|
39
|
-
* `loadSession` from `../../utils/config`
|
|
40
|
-
* `logger` from `../../utils/logger`
|
|
41
|
-
* `ora`
|
|
42
|
-
* `pushToDatabase` from `../../db/index`
|
|
43
|
-
|
|
44
|
-
## Usage Example
|
|
45
|
-
No clear pattern is visible in the code, but the function can be used as follows:
|
|
46
|
-
```bash
|
|
47
|
-
legacyver push [target]
|
|
48
|
-
```
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This module exports a function `versionCommand` that prints the version of the package to the console.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### versionCommand
|
|
6
|
-
Prints the version of the package to the console.
|
|
7
|
-
|
|
8
|
-
| Param | Type | Description |
|
|
9
|
-
| --- | --- | --- |
|
|
10
|
-
| None | | |
|
|
11
|
-
|
|
12
|
-
| Return Value | Type | Description |
|
|
13
|
-
| --- | --- | --- |
|
|
14
|
-
| None | | |
|
|
15
|
-
|
|
16
|
-
## Dependencies
|
|
17
|
-
* `fs: readFileSync`
|
|
18
|
-
* `path: join`
|
|
19
|
-
|
|
20
|
-
## Usage Example
|
|
21
|
-
The function can be used as follows:
|
|
22
|
-
```javascript
|
|
23
|
-
const version = require('./version');
|
|
24
|
-
version.versionCommand();
|
|
25
|
-
```
|
|
26
|
-
This will print the version of the package to the console.
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This module exports four functions for creating a spinner, progress bar, confirming a prompt, and printing a summary of analysis results.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
|
|
6
|
-
### createSpinner(text)
|
|
7
|
-
Creates a spinner object for displaying a text message.
|
|
8
|
-
|
|
9
|
-
| Param | Type | Description |
|
|
10
|
-
| --- | --- | --- |
|
|
11
|
-
| text | string | The text to display in the spinner |
|
|
12
|
-
|
|
13
|
-
| Return Value | Type | Description |
|
|
14
|
-
| --- | --- | --- |
|
|
15
|
-
| object | | An object with methods for starting, succeeding, failing, warning, stopping, and getting the text |
|
|
16
|
-
|
|
17
|
-
#### Usage
|
|
18
|
-
```javascript
|
|
19
|
-
const spinner = createSpinner('Analyzing...');
|
|
20
|
-
spinner.start('Starting...');
|
|
21
|
-
spinner.succeed('Done!');
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### createProgressBar(total)
|
|
25
|
-
Creates a progress bar object for displaying a progress bar.
|
|
26
|
-
|
|
27
|
-
| Param | Type | Description |
|
|
28
|
-
| --- | --- | --- |
|
|
29
|
-
| total | number | The total number of items to process |
|
|
30
|
-
|
|
31
|
-
| Return Value | Type | Description |
|
|
32
|
-
| --- | --- | --- |
|
|
33
|
-
| object | | An object with methods for starting, incrementing, and stopping the progress bar |
|
|
34
|
-
|
|
35
|
-
#### Usage
|
|
36
|
-
```javascript
|
|
37
|
-
const progressBar = createProgressBar(100);
|
|
38
|
-
progressBar.start();
|
|
39
|
-
for (let i = 0; i < 100; i++) {
|
|
40
|
-
progressBar.increment();
|
|
41
|
-
}
|
|
42
|
-
progressBar.stop();
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### confirmPrompt(message)
|
|
46
|
-
Asynchronously confirms a prompt with the user.
|
|
47
|
-
|
|
48
|
-
| Param | Type | Description |
|
|
49
|
-
| --- | --- | --- |
|
|
50
|
-
| message | string | The message to display to the user |
|
|
51
|
-
|
|
52
|
-
| Return Value | Type | Description |
|
|
53
|
-
| --- | --- | --- |
|
|
54
|
-
| Promise | | A promise that resolves to a boolean indicating whether the user confirmed |
|
|
55
|
-
|
|
56
|
-
#### Usage
|
|
57
|
-
```javascript
|
|
58
|
-
confirmPrompt('Are you sure?').then((confirmed) => {
|
|
59
|
-
if (confirmed) {
|
|
60
|
-
console.log('Confirmed!');
|
|
61
|
-
} else {
|
|
62
|
-
console.log('Not confirmed!');
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### printSummary(stats)
|
|
68
|
-
Prints a summary of analysis results.
|
|
69
|
-
|
|
70
|
-
| Param | Type | Description |
|
|
71
|
-
| --- | --- | --- |
|
|
72
|
-
| stats | object | The analysis results |
|
|
73
|
-
|
|
74
|
-
| Return Value | Type | Description |
|
|
75
|
-
| --- | --- | --- |
|
|
76
|
-
| void | | No return value |
|
|
77
|
-
|
|
78
|
-
#### Usage
|
|
79
|
-
```javascript
|
|
80
|
-
const stats = { filesAnalyzed: 100, filesCached: 20, filesSkipped: 10 };
|
|
81
|
-
printSummary(stats);
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Dependencies
|
|
85
|
-
|
|
86
|
-
* `ora`: for creating a spinner
|
|
87
|
-
* `cli-progress`: for creating a progress bar
|
|
88
|
-
* `readline`: for reading input from the user
|
|
89
|
-
* `picocolors`: for coloring console output
|
|
90
|
-
* `../utils/config`: for loading the session configuration
|
|
91
|
-
|
|
92
|
-
## Usage Example
|
|
93
|
-
```javascript
|
|
94
|
-
const { createSpinner, createProgressBar, confirmPrompt, printSummary } = require('./cli/ui');
|
|
95
|
-
|
|
96
|
-
const spinner = createSpinner('Analyzing...');
|
|
97
|
-
spinner.start('Starting...');
|
|
98
|
-
confirmPrompt('Are you sure?').then((confirmed) => {
|
|
99
|
-
if (confirmed) {
|
|
100
|
-
const progressBar = createProgressBar(100);
|
|
101
|
-
progressBar.start();
|
|
102
|
-
for (let i = 0; i < 100; i++) {
|
|
103
|
-
progressBar.increment();
|
|
104
|
-
}
|
|
105
|
-
progressBar.stop();
|
|
106
|
-
const stats = { filesAnalyzed: 100, filesCached: 20, filesSkipped: 10 };
|
|
107
|
-
printSummary(stats);
|
|
108
|
-
} else {
|
|
109
|
-
console.log('Not confirmed!');
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
```
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This module provides functions for detecting the language of a file based on its extension and detecting the primary language of a list of files.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
|
|
6
|
-
### detectLanguage(ext)
|
|
7
|
-
Detects the language of a file based on its extension.
|
|
8
|
-
|
|
9
|
-
| Param | Type | Description |
|
|
10
|
-
| --- | --- | --- |
|
|
11
|
-
| ext | string | The file extension to detect the language for |
|
|
12
|
-
|
|
13
|
-
| Return Value | Type | Description |
|
|
14
|
-
| --- | --- | --- |
|
|
15
|
-
| language | string | The detected language, or null if not found |
|
|
16
|
-
|
|
17
|
-
### detectPrimaryLanguage(files)
|
|
18
|
-
Detects the primary language of a list of files.
|
|
19
|
-
|
|
20
|
-
| Param | Type | Description |
|
|
21
|
-
| --- | --- | --- |
|
|
22
|
-
| files | array | The list of files to detect the primary language for |
|
|
23
|
-
|
|
24
|
-
| Return Value | Type | Description |
|
|
25
|
-
| --- | --- | --- |
|
|
26
|
-
| language | string | The primary language detected |
|
|
27
|
-
|
|
28
|
-
## Dependencies
|
|
29
|
-
* `Object.entries()`
|
|
30
|
-
* `Object.values()`
|
|
31
|
-
* `flat()`
|
|
32
|
-
|
|
33
|
-
## Usage Example
|
|
34
|
-
```javascript
|
|
35
|
-
const files = [
|
|
36
|
-
{ language: 'javascript' },
|
|
37
|
-
{ language: 'typescript' },
|
|
38
|
-
{ language: 'javascript' },
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
const primaryLanguage = detectPrimaryLanguage(files);
|
|
42
|
-
console.log(primaryLanguage); // Output: javascript
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Based on the provided code, here are the documentation for the missing exported symbols:
|
|
46
|
-
|
|
47
|
-
## LANGUAGE_EXTENSIONS
|
|
48
|
-
A list of language extensions supported by the module.
|
|
49
|
-
|
|
50
|
-
## ALL_EXTENSIONS
|
|
51
|
-
A list of all extensions supported by the module.
|
|
52
|
-
|
|
53
|
-
## DEFAULT_IGNORE_PATTERNS
|
|
54
|
-
A list of default patterns to ignore when processing files.
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This is a JavaScript module that exports a single function, `crawl`, which is the main entrypoint for a file crawler. The `crawl` function takes a target directory and a configuration object as input and returns an object containing a list of files, skipped files, and metadata about the crawled directory.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### crawl
|
|
6
|
-
#### Description
|
|
7
|
-
The `crawl` function is the main entrypoint for the file crawler. It takes a target directory and a configuration object as input and returns an object containing a list of files, skipped files, and metadata about the crawled directory.
|
|
8
|
-
|
|
9
|
-
#### Parameters
|
|
10
|
-
| Name | Type | Description |
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| targetDir | string | The target directory to crawl. |
|
|
13
|
-
| config | Object | The configuration object for the crawler. |
|
|
14
|
-
|
|
15
|
-
#### Return Value
|
|
16
|
-
An object containing the following properties:
|
|
17
|
-
| Name | Type | Description |
|
|
18
|
-
| --- | --- | --- |
|
|
19
|
-
| files | FileManifest[] | A list of files in the crawled directory. |
|
|
20
|
-
| skipped | Object[] | A list of files that were skipped due to size or other reasons. |
|
|
21
|
-
| meta | Object | Metadata about the crawled directory, including the primary language, framework, and total number of files. |
|
|
22
|
-
|
|
23
|
-
#### Body Logic
|
|
24
|
-
The `crawl` function performs the following steps:
|
|
25
|
-
1. Calculates the maximum file size in bytes based on the configuration object.
|
|
26
|
-
2. Walks the target directory using the `walk` function and builds a manifest of files using the `buildManifest` function.
|
|
27
|
-
3. Applies a size filter to the manifest, skipping files that exceed the maximum size.
|
|
28
|
-
4. Detects the primary language of the files using the `detectPrimaryLanguage` function.
|
|
29
|
-
5. Detects whether the directory is a Laravel project by checking for the presence of the `artisan` and `app` directories.
|
|
30
|
-
6. Returns an object containing the filtered files, skipped files, and metadata about the crawled directory.
|
|
31
|
-
|
|
32
|
-
## Dependencies
|
|
33
|
-
* `fs`: for the `existsSync` function
|
|
34
|
-
* `path`: for path manipulation
|
|
35
|
-
* `./walk`: for walking the target directory
|
|
36
|
-
* `./manifest`: for building the file manifest
|
|
37
|
-
* `./filters`: for detecting the primary language
|
|
38
|
-
* `../utils/logger`: for logging messages
|
|
39
|
-
|
|
40
|
-
## Usage Example
|
|
41
|
-
```javascript
|
|
42
|
-
const { crawl } = require('./index');
|
|
43
|
-
|
|
44
|
-
const targetDir = '/path/to/directory';
|
|
45
|
-
const config = {
|
|
46
|
-
maxFileSizeKb: 1024,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
crawl(targetDir, config).then((result) => {
|
|
50
|
-
console.log(result.files);
|
|
51
|
-
console.log(result.skipped);
|
|
52
|
-
console.log(result.meta);
|
|
53
|
-
});
|
|
54
|
-
```
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
The `buildManifest` function generates a list of file manifests from a list of absolute file paths.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### buildManifest
|
|
6
|
-
Build a FileManifest[] from a list of absolute paths.
|
|
7
|
-
|
|
8
|
-
| Parameter | Type | Description |
|
|
9
|
-
| --- | --- | --- |
|
|
10
|
-
| absPaths | string[] | List of absolute file paths. |
|
|
11
|
-
| targetDir | string | Target directory for relative path calculation. |
|
|
12
|
-
|
|
13
|
-
Returns: `import('./index').FileManifest[]`
|
|
14
|
-
|
|
15
|
-
## Dependencies
|
|
16
|
-
* `crypto: createHash`
|
|
17
|
-
* `fs: statSync, readFileSync`
|
|
18
|
-
* `path: path`
|
|
19
|
-
* `./filters: detectLanguage`
|
|
20
|
-
|
|
21
|
-
## Usage Example
|
|
22
|
-
The `buildManifest` function takes a list of absolute file paths and a target directory, and returns a list of file manifests. Each file manifest contains the relative path, absolute path, language, size in bytes, and SHA-256 hash of the file. If a file is unreadable, its hash is set to `null`.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
The `walk` function is used to walk a directory and return all matching source file paths. It takes a target directory and a configuration object as input.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### walk
|
|
6
|
-
* Description: Walk a directory and return all matching source file paths.
|
|
7
|
-
* Parameters:
|
|
8
|
-
+ `targetDir`: The target directory to walk.
|
|
9
|
-
+ `config`: The configuration object.
|
|
10
|
-
* Return Value: An array of absolute paths.
|
|
11
|
-
|
|
12
|
-
## Dependencies
|
|
13
|
-
* `fast-glob`: `fg`
|
|
14
|
-
* `ignore`: `ignore`
|
|
15
|
-
* `fs`: `readFileSync`, `existsSync`
|
|
16
|
-
* `path`: `path`
|
|
17
|
-
* `./filters`: `DEFAULT_IGNORE_PATTERNS`, `ALL_EXTENSIONS`
|
|
18
|
-
|
|
19
|
-
## Usage Example
|
|
20
|
-
The `walk` function can be used as follows:
|
|
21
|
-
```javascript
|
|
22
|
-
const walk = require('./walk');
|
|
23
|
-
const targetDir = '/path/to/directory';
|
|
24
|
-
const config = {};
|
|
25
|
-
|
|
26
|
-
const paths = await walk(targetDir, config);
|
|
27
|
-
console.log(paths);
|
|
28
|
-
```
|
|
29
|
-
Note: The usage example is not directly extracted from the code, but rather inferred based on the function's purpose and parameters.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This module exports a PostgreSQL connection configuration for the Legacyver hackathon database, using SSL with a self-signed certificate.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### None
|
|
6
|
-
|
|
7
|
-
## Dependencies
|
|
8
|
-
* `module.exports`
|
|
9
|
-
|
|
10
|
-
## Usage Example
|
|
11
|
-
None, as this module only exports a configuration object.
|
|
12
|
-
|
|
13
|
-
Note: This module does not contain any functions, only a configuration object that is exported. The usage example is not applicable in this case.
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This module provides a set of functions for interacting with a PostgreSQL database, specifically for managing repositories and documentation. It uses a lazy singleton pool to connect to the database.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
|
|
6
|
-
### getPool
|
|
7
|
-
#### Description
|
|
8
|
-
Lazy singleton pool — created on first use, ended after push.
|
|
9
|
-
#### Parameters
|
|
10
|
-
| Name | Type | Description |
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| None | | |
|
|
13
|
-
#### Return Value
|
|
14
|
-
`Pool` instance
|
|
15
|
-
|
|
16
|
-
### getOrCreateRepo
|
|
17
|
-
#### Description
|
|
18
|
-
Find or create a repository for the given user + project path.
|
|
19
|
-
#### Parameters
|
|
20
|
-
| Name | Type | Description |
|
|
21
|
-
| --- | --- | --- |
|
|
22
|
-
| pool | `Pool` | Database connection pool |
|
|
23
|
-
| userId | `string` | User ID (BIGINT as string) |
|
|
24
|
-
| projectPath | `string` | Absolute path of the analyzed directory |
|
|
25
|
-
#### Return Value
|
|
26
|
-
`Promise<string>` repository ID (UUID)
|
|
27
|
-
|
|
28
|
-
### getOrCreateDocumentation
|
|
29
|
-
#### Description
|
|
30
|
-
Find or create a documentation record for a repository.
|
|
31
|
-
#### Parameters
|
|
32
|
-
| Name | Type | Description |
|
|
33
|
-
| --- | --- | --- |
|
|
34
|
-
| pool | `Pool` | Database connection pool |
|
|
35
|
-
| repositoryId | `string` | Repository ID (UUID) |
|
|
36
|
-
| repoName | `string` | Repository name |
|
|
37
|
-
#### Return Value
|
|
38
|
-
`Promise<string>` documentation ID (UUID)
|
|
39
|
-
|
|
40
|
-
### upsertPages
|
|
41
|
-
#### Description
|
|
42
|
-
Upsert documentation pages.
|
|
43
|
-
#### Parameters
|
|
44
|
-
| Name | Type | Description |
|
|
45
|
-
| --- | --- | --- |
|
|
46
|
-
| pool | `Pool` | Database connection pool |
|
|
47
|
-
| documentationId | `string` | Documentation ID (UUID) |
|
|
48
|
-
| fragments | `Array<{relativePath: string, content: string}>` | Array of fragments to upsert |
|
|
49
|
-
#### Return Value
|
|
50
|
-
`Promise<number>` count of upserted pages
|
|
51
|
-
|
|
52
|
-
### pushToDatabase
|
|
53
|
-
#### Description
|
|
54
|
-
Top-level push function. Called from analyze command.
|
|
55
|
-
#### Parameters
|
|
56
|
-
| Name | Type | Description |
|
|
57
|
-
| --- | --- | --- |
|
|
58
|
-
| fragments | `Array<{relativePath: string, content: string}>` | Array of fragments to push |
|
|
59
|
-
| projectPath | `string` | Absolute path of the analyzed directory |
|
|
60
|
-
| [opts] | `object` | Optional overrides for testing |
|
|
61
|
-
| [opts.pool] | `object` | PG Pool instance (skips singleton pool) |
|
|
62
|
-
| [opts.session] | `object` | Session object (skips loadSession) |
|
|
63
|
-
| [opts.user] | `object` | User object (skips validateToken) — { userId, username, email } |
|
|
64
|
-
#### Return Value
|
|
65
|
-
`Promise<{skipped: boolean, pushed?: number}>`
|
|
66
|
-
|
|
67
|
-
## Dependencies
|
|
68
|
-
|
|
69
|
-
* `pg: Pool`
|
|
70
|
-
* `path: path`
|
|
71
|
-
* `./config: dbConfig`
|
|
72
|
-
* `../utils/config: loadSession`
|
|
73
|
-
* `../api/auth: validateToken`
|
|
74
|
-
* `../utils/logger: logger`
|
|
75
|
-
|
|
76
|
-
## Usage Example
|
|
77
|
-
```javascript
|
|
78
|
-
const pool = getPool();
|
|
79
|
-
const repoId = await getOrCreateRepo(pool, '1234567890', '/path/to/project');
|
|
80
|
-
const docId = await getOrCreateDocumentation(pool, repoId, 'my-repo');
|
|
81
|
-
const pushed = await upsertPages(pool, docId, [
|
|
82
|
-
{ relativePath: 'file1.md', content: 'Hello world!' },
|
|
83
|
-
{ relativePath: 'file2.md', content: 'Foo bar!' },
|
|
84
|
-
]);
|
|
85
|
-
console.log(pushed); // 2
|
|
86
|
-
```
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
The `buildChunks` function builds LLM request chunks from a given package (`pkg`) and configuration (`config`). It processes each file in the package, truncating the source if necessary to fit within a token count limit.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
### buildChunks
|
|
6
|
-
#### Description
|
|
7
|
-
Builds LLM request chunks from a given package (`pkg`) and configuration (`config`).
|
|
8
|
-
|
|
9
|
-
#### Parameters
|
|
10
|
-
| Name | Type | Description |
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| `pkg` | `Object` | The package to process. |
|
|
13
|
-
| `config` | `Object` | The configuration to use. |
|
|
14
|
-
|
|
15
|
-
#### Return Value
|
|
16
|
-
`Array<{relativePath, systemPrompt, userMessage, tokenCount}>`
|
|
17
|
-
|
|
18
|
-
#### Detected Patterns
|
|
19
|
-
* Arithmetic operations are used to calculate the token count and budget characters.
|
|
20
|
-
|
|
21
|
-
## Dependencies
|
|
22
|
-
* `fs: readFileSync`
|
|
23
|
-
* `./prompts: SYSTEM_PROMPT, buildUserMessage`
|
|
24
|
-
* `./cost-estimator: countTokens`
|
|
25
|
-
* `../utils/logger: logger`
|
|
26
|
-
|
|
27
|
-
## Usage Example
|
|
28
|
-
Based on the code, it appears that the function is designed to be used in a loop, processing each file in the package. The `buildChunks` function returns an array of objects, each containing the relative path, system prompt, user message, and token count for a given file.
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
This module provides functions for estimating the cost of using Large Language Models (LLMs) based on the input text and model pricing data. It uses the tiktoken library to estimate token counts and fetches model pricing data from the OpenRouter API.
|
|
3
|
-
|
|
4
|
-
## Functions
|
|
5
|
-
|
|
6
|
-
### countTokens(text)
|
|
7
|
-
Counts the number of tokens in the given text.
|
|
8
|
-
|
|
9
|
-
#### Parameters
|
|
10
|
-
| Name | Type | Description |
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| text | string | The text to count tokens for |
|
|
13
|
-
|
|
14
|
-
#### Return Value
|
|
15
|
-
The number of tokens in the text.
|
|
16
|
-
|
|
17
|
-
#### Description
|
|
18
|
-
This function uses the tiktoken library to encode the text and return the length of the encoded string. If the tiktoken library is not available, it falls back to a rough approximation of 1 token per 4 characters.
|
|
19
|
-
|
|
20
|
-
### fetchModelPricing()
|
|
21
|
-
Fetches the model pricing data from the OpenRouter API or returns a cached version if it is still valid.
|
|
22
|
-
|
|
23
|
-
#### Return Value
|
|
24
|
-
A promise resolving to an object with model pricing data.
|
|
25
|
-
|
|
26
|
-
#### Description
|
|
27
|
-
This function checks if the model pricing cache is still valid (within the last hour). If it is, it returns the cached data. Otherwise, it fetches the data from the OpenRouter API, parses the response, and caches the result.
|
|
28
|
-
|
|
29
|
-
### estimateCost(chunks, config)
|
|
30
|
-
Estimates the cost of a list of LLM request chunks.
|
|
31
|
-
|
|
32
|
-
#### Parameters
|
|
33
|
-
| Name | Type | Description |
|
|
34
|
-
| --- | --- | --- |
|
|
35
|
-
| chunks | Array | The list of LLM request chunks |
|
|
36
|
-
| config | Object | The configuration object with a `model` property |
|
|
37
|
-
|
|
38
|
-
#### Return Value
|
|
39
|
-
A promise resolving to an object with the estimated cost data.
|
|
40
|
-
|
|
41
|
-
#### Description
|
|
42
|
-
This function uses the `fetchModelPricing` function to get the model pricing data for the specified model. It then calculates the total input tokens by summing the tokens in each chunk's system prompt and user message. It also calculates the total output tokens based on an average of 400 tokens per chunk. The estimated cost is then calculated by multiplying the total input tokens by the input price and the total output tokens by the output price.
|
|
43
|
-
|
|
44
|
-
## Dependencies
|
|
45
|
-
* `fs`: `readFileSync`
|
|
46
|
-
* `path`: `path`
|
|
47
|
-
* `../utils/logger`: `logger`
|
|
48
|
-
* `tiktoken`: `get_encoding`
|
|
49
|
-
|
|
50
|
-
## Usage Example
|
|
51
|
-
```javascript
|
|
52
|
-
const chunks = [
|
|
53
|
-
{ systemPrompt: 'Hello, world!', userMessage: 'How are you?' },
|
|
54
|
-
{ systemPrompt: 'What is your name?', userMessage: 'John' },
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
const config = { model: 'meta-llama/llama-3.3-70b-instruct:free' };
|
|
58
|
-
|
|
59
|
-
estimateCost(chunks, config).then((cost) => {
|
|
60
|
-
console.log(cost);
|
|
61
|
-
});
|
|
62
|
-
```
|