@reverse-craft/smart-fs 1.0.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -1
- package/dist/analyzer.d.ts +91 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/beautifier.d.ts +120 -0
- package/dist/beautifier.d.ts.map +1 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1267 -0
- package/dist/index.js.map +7 -0
- package/dist/languageDetector.d.ts +74 -0
- package/dist/languageDetector.d.ts.map +1 -0
- package/dist/llmConfig.d.ts +34 -0
- package/dist/llmConfig.d.ts.map +1 -0
- package/dist/searcher.d.ts +113 -0
- package/dist/searcher.d.ts.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +537 -41
- package/dist/server.js.map +4 -4
- package/dist/tools/ToolDefinition.d.ts +24 -0
- package/dist/tools/ToolDefinition.d.ts.map +1 -0
- package/dist/tools/aiFindJsvmpDispatcher.d.ts +79 -0
- package/dist/tools/aiFindJsvmpDispatcher.d.ts.map +1 -0
- package/dist/tools/applyCustomTransform.d.ts +14 -0
- package/dist/tools/applyCustomTransform.d.ts.map +1 -0
- package/dist/tools/findUsageSmart.d.ts +16 -0
- package/dist/tools/findUsageSmart.d.ts.map +1 -0
- package/dist/tools/index.d.ts +43 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/readCodeSmart.d.ts +13 -0
- package/dist/tools/readCodeSmart.d.ts.map +1 -0
- package/dist/tools/searchCodeSmart.d.ts +18 -0
- package/dist/tools/searchCodeSmart.d.ts.map +1 -0
- package/dist/transformer.d.ts +119 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/truncator.d.ts +69 -0
- package/dist/truncator.d.ts.map +1 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Or if installed globally:
|
|
|
48
48
|
|
|
49
49
|
## Usage
|
|
50
50
|
|
|
51
|
-
The server provides
|
|
51
|
+
The server provides five tools:
|
|
52
52
|
|
|
53
53
|
### 1. read_code_smart
|
|
54
54
|
|
|
@@ -139,6 +139,87 @@ Matches: 3
|
|
|
139
139
|
44 L1:1100
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
### 4. apply_custom_transform
|
|
143
|
+
|
|
144
|
+
Apply a custom Babel transformation to deobfuscate JavaScript code.
|
|
145
|
+
|
|
146
|
+
#### Parameters
|
|
147
|
+
|
|
148
|
+
| Parameter | Type | Required | Default | Description |
|
|
149
|
+
|-----------|------|----------|---------|-------------|
|
|
150
|
+
| `target_file` | string | ✓ | - | Path to the JavaScript file to transform |
|
|
151
|
+
| `script_path` | string | ✓ | - | Path to a JS file exporting a Babel Plugin function |
|
|
152
|
+
| `output_suffix` | string | | _deob | Suffix for output file name |
|
|
153
|
+
|
|
154
|
+
#### Example Plugin Script
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
// deob-plugin.js
|
|
158
|
+
module.exports = function() {
|
|
159
|
+
return {
|
|
160
|
+
visitor: {
|
|
161
|
+
// Evaluate constant binary expressions: "a" + "b" -> "ab"
|
|
162
|
+
BinaryExpression(path) {
|
|
163
|
+
const { left, right, operator } = path.node;
|
|
164
|
+
if (operator === '+' &&
|
|
165
|
+
left.type === 'StringLiteral' &&
|
|
166
|
+
right.type === 'StringLiteral') {
|
|
167
|
+
path.replaceWith({ type: 'StringLiteral', value: left.value + right.value });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### Example Output
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
Transform completed successfully!
|
|
179
|
+
|
|
180
|
+
Output file: /path/to/obfuscated_deob.js
|
|
181
|
+
Source map: /path/to/obfuscated_deob.js.map
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The output file includes a cascaded source map that traces back to the original minified file, so breakpoints still work in Chrome DevTools.
|
|
185
|
+
|
|
186
|
+
### 5. ai_find_jsvmp_dispatcher
|
|
187
|
+
|
|
188
|
+
AI-powered tool to find JSVMP (JavaScript Virtual Machine Protection) dispatcher patterns in code using LLM analysis. Requires `OPENAI_API_KEY` environment variable.
|
|
189
|
+
|
|
190
|
+
#### Parameters
|
|
191
|
+
|
|
192
|
+
| Parameter | Type | Required | Default | Description |
|
|
193
|
+
|-----------|------|----------|---------|-------------|
|
|
194
|
+
| `file_path` | string | ✓ | - | Path to JavaScript file |
|
|
195
|
+
| `start_line` | number | ✓ | - | Start line (1-based) |
|
|
196
|
+
| `end_line` | number | ✓ | - | End line (1-based) |
|
|
197
|
+
| `char_limit` | number | | 300 | Max string length before truncation |
|
|
198
|
+
|
|
199
|
+
#### Environment Variables
|
|
200
|
+
|
|
201
|
+
| Variable | Required | Default | Description |
|
|
202
|
+
|----------|----------|---------|-------------|
|
|
203
|
+
| `OPENAI_API_KEY` | ✓ | - | OpenAI API key |
|
|
204
|
+
| `OPENAI_BASE_URL` | | `https://api.openai.com/v1` | API base URL |
|
|
205
|
+
| `OPENAI_MODEL` | | `gpt-4o-mini` | Model name |
|
|
206
|
+
|
|
207
|
+
#### Example Output
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
=== JSVMP Dispatcher Detection Result ===
|
|
211
|
+
File: /path/to/obfuscated.js (100-500)
|
|
212
|
+
|
|
213
|
+
Summary: 检测到 JSVMP 保护代码,包含主分发器和虚拟栈操作
|
|
214
|
+
|
|
215
|
+
Detected Regions:
|
|
216
|
+
[ultra_high] Lines 150-300: Switch Dispatcher
|
|
217
|
+
大型 switch 语句,包含 50+ case 分支,典型的 JSVMP 分发器结构
|
|
218
|
+
|
|
219
|
+
[high] Lines 120-140: Stack Operation
|
|
220
|
+
数组操作模式,疑似虚拟栈实现
|
|
221
|
+
```
|
|
222
|
+
|
|
142
223
|
The `Src L:C` shows the original position in the minified file - use these coordinates to set breakpoints in Chrome DevTools.
|
|
143
224
|
|
|
144
225
|
## Features
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { SourceMap } from './beautifier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Original position from source map
|
|
4
|
+
*/
|
|
5
|
+
export interface OriginalPosition {
|
|
6
|
+
line: number | null;
|
|
7
|
+
column: number | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Location information for a definition or reference
|
|
11
|
+
*/
|
|
12
|
+
export interface LocationInfo {
|
|
13
|
+
/** Line number in beautified code (1-based) */
|
|
14
|
+
line: number;
|
|
15
|
+
/** Column number in beautified code (0-based) */
|
|
16
|
+
column: number;
|
|
17
|
+
/** Original file coordinates from source map */
|
|
18
|
+
originalPosition: OriginalPosition;
|
|
19
|
+
/** Content of the line containing this location */
|
|
20
|
+
lineContent: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Binding information for a variable/function
|
|
24
|
+
*/
|
|
25
|
+
export interface BindingInfo {
|
|
26
|
+
/** Unique scope identifier */
|
|
27
|
+
scopeUid: number;
|
|
28
|
+
/** Binding kind (var, let, const, param, etc.) */
|
|
29
|
+
kind: string;
|
|
30
|
+
/** Definition location */
|
|
31
|
+
definition: LocationInfo;
|
|
32
|
+
/** All reference locations */
|
|
33
|
+
references: LocationInfo[];
|
|
34
|
+
/** Total reference count (before limiting) */
|
|
35
|
+
totalReferences: number;
|
|
36
|
+
/** The location that matched the target line (if targeted search) */
|
|
37
|
+
hitLocation?: LocationInfo;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Analysis result containing all bindings for an identifier
|
|
41
|
+
*/
|
|
42
|
+
export interface AnalysisResult {
|
|
43
|
+
/** All bindings found for the identifier */
|
|
44
|
+
bindings: BindingInfo[];
|
|
45
|
+
/** The identifier that was searched */
|
|
46
|
+
identifier: string;
|
|
47
|
+
/** Whether this was a targeted (line-specific) search */
|
|
48
|
+
isTargeted: boolean;
|
|
49
|
+
/** The target line if specified */
|
|
50
|
+
targetLine?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parse JavaScript/TypeScript code into an AST
|
|
54
|
+
* @param code - Source code to parse
|
|
55
|
+
* @returns Parsed AST
|
|
56
|
+
* @throws Error if parsing fails
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseCode(code: string): import("@babel/parser").ParseResult<import("@babel/types").File>;
|
|
59
|
+
/**
|
|
60
|
+
* Options for binding analysis
|
|
61
|
+
*/
|
|
62
|
+
export interface AnalyzeOptions {
|
|
63
|
+
/** Maximum references to return per binding (default 10) */
|
|
64
|
+
maxReferences?: number;
|
|
65
|
+
/** Target line number for precise binding identification (1-based) */
|
|
66
|
+
targetLine?: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Analyze bindings for a specific identifier in the code
|
|
70
|
+
* Uses Babel traverse to find all bindings and their references
|
|
71
|
+
*
|
|
72
|
+
* @param code - Beautified code to analyze
|
|
73
|
+
* @param rawMap - Source map for coordinate mapping
|
|
74
|
+
* @param identifier - Variable/function name to find
|
|
75
|
+
* @param options - Analysis options
|
|
76
|
+
* @returns Analysis result with all bindings
|
|
77
|
+
*/
|
|
78
|
+
export declare function analyzeBindings(code: string, rawMap: SourceMap, identifier: string, options?: AnalyzeOptions): Promise<AnalysisResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Format source position as "L{line}:{column}" or placeholder
|
|
81
|
+
*/
|
|
82
|
+
export declare function formatSourcePosition(line: number | null, column: number | null): string;
|
|
83
|
+
/**
|
|
84
|
+
* Format analysis result for output
|
|
85
|
+
* @param filePath - Path to the file
|
|
86
|
+
* @param result - Analysis result
|
|
87
|
+
* @param maxReferences - Maximum references shown per binding
|
|
88
|
+
* @returns Formatted output string
|
|
89
|
+
*/
|
|
90
|
+
export declare function formatAnalysisResult(filePath: string, result: AnalysisResult, maxReferences?: number): string;
|
|
91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4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,cAAc,CAAC,CAkIzB;AAGD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKvF;AAmBD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,EACtB,aAAa,GAAE,MAAW,GACzB,MAAM,CAmFR"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type SupportedLanguage } from './languageDetector.js';
|
|
2
|
+
export interface SourceMap {
|
|
3
|
+
version: number;
|
|
4
|
+
sources: string[];
|
|
5
|
+
names: string[];
|
|
6
|
+
mappings: string;
|
|
7
|
+
file?: string;
|
|
8
|
+
sourceRoot?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BeautifyOptions {
|
|
11
|
+
/** Override auto-detected language */
|
|
12
|
+
language?: SupportedLanguage;
|
|
13
|
+
/** Save beautified file locally (default: true for JS/TS) */
|
|
14
|
+
saveLocal?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface BeautifyResult {
|
|
17
|
+
code: string;
|
|
18
|
+
/** Source map (null for languages that don't support it) */
|
|
19
|
+
rawMap: SourceMap | null;
|
|
20
|
+
/** 本地保存的美化文件路径 */
|
|
21
|
+
localPath: string;
|
|
22
|
+
/** 本地保存的 source map 路径 */
|
|
23
|
+
localMapPath: string;
|
|
24
|
+
/** 本地保存失败时的错误信息 */
|
|
25
|
+
localSaveError?: string;
|
|
26
|
+
/** Whether fallback mode was used */
|
|
27
|
+
usedFallback: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Local paths result interface
|
|
31
|
+
*/
|
|
32
|
+
export interface LocalPaths {
|
|
33
|
+
/** Path to the beautified file in the same directory as the original */
|
|
34
|
+
beautifiedPath: string;
|
|
35
|
+
/** Path to the source map file in the same directory as the original */
|
|
36
|
+
mapPath: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get local file paths for beautified output
|
|
40
|
+
* Given an original file path, returns the paths where the beautified file
|
|
41
|
+
* and source map should be saved in the same directory.
|
|
42
|
+
*
|
|
43
|
+
* Naming convention:
|
|
44
|
+
* - Original: {filename}.js -> Beautified: {filename}.beautified.js
|
|
45
|
+
* - Source map: {filename}.beautified.js.map
|
|
46
|
+
*
|
|
47
|
+
* @param originalPath - Path to the original JavaScript file
|
|
48
|
+
* @returns Object containing beautifiedPath and mapPath
|
|
49
|
+
*/
|
|
50
|
+
export declare function getLocalPaths(originalPath: string): LocalPaths;
|
|
51
|
+
/**
|
|
52
|
+
* Local cache validation result interface
|
|
53
|
+
*/
|
|
54
|
+
export interface LocalCacheCheck {
|
|
55
|
+
/** Original file modification time in milliseconds */
|
|
56
|
+
originalMtime: number;
|
|
57
|
+
/** Whether the beautified file exists */
|
|
58
|
+
beautifiedExists: boolean;
|
|
59
|
+
/** Beautified file modification time in milliseconds (0 if not exists) */
|
|
60
|
+
beautifiedMtime: number;
|
|
61
|
+
/** Whether the cache is valid (beautifiedMtime >= originalMtime) */
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if local beautified cache is valid
|
|
66
|
+
*
|
|
67
|
+
* A local cache is considered valid when:
|
|
68
|
+
* 1. The beautified file exists
|
|
69
|
+
* 2. The beautified file's modification time is >= the original file's modification time
|
|
70
|
+
*
|
|
71
|
+
* @param originalPath - Path to the original JavaScript file
|
|
72
|
+
* @returns LocalCacheCheck object with validation details
|
|
73
|
+
*/
|
|
74
|
+
export declare function isLocalCacheValid(originalPath: string): Promise<LocalCacheCheck>;
|
|
75
|
+
/**
|
|
76
|
+
* Beautify JSON content with proper indentation
|
|
77
|
+
* @param content - JSON string to beautify
|
|
78
|
+
* @returns Object with beautified JSON string and error flag
|
|
79
|
+
*/
|
|
80
|
+
export declare function beautifyJson(content: string): {
|
|
81
|
+
code: string;
|
|
82
|
+
parseFailed: boolean;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Simple HTML/XML beautification with indentation
|
|
86
|
+
* This is a basic formatter that handles common cases
|
|
87
|
+
* @param content - HTML/XML string to beautify
|
|
88
|
+
* @returns Beautified HTML/XML string, or original content if formatting fails
|
|
89
|
+
*/
|
|
90
|
+
export declare function beautifyHtml(content: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* Simple CSS beautification with indentation
|
|
93
|
+
* @param content - CSS string to beautify
|
|
94
|
+
* @returns Beautified CSS string, or original content if formatting fails
|
|
95
|
+
*/
|
|
96
|
+
export declare function beautifyCss(content: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Beautify code string directly based on language
|
|
99
|
+
* @param code - Source code to beautify
|
|
100
|
+
* @param language - Language type
|
|
101
|
+
* @returns Beautified code (or original if fallback mode)
|
|
102
|
+
*/
|
|
103
|
+
export declare function beautifyCode(code: string, language: SupportedLanguage): {
|
|
104
|
+
code: string;
|
|
105
|
+
usedFallback: boolean;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Beautify file based on detected or specified language
|
|
109
|
+
* - JS/TS: Use esbuild for formatting with source map
|
|
110
|
+
* - JSON: Use JSON.stringify with indentation
|
|
111
|
+
* - HTML/XML: Use simple indentation-based formatting
|
|
112
|
+
* - CSS: Use simple formatting
|
|
113
|
+
* - Unknown: Return original (fallback mode)
|
|
114
|
+
*
|
|
115
|
+
* @param originalPath - Original file path
|
|
116
|
+
* @param options - Optional beautify options (language, saveLocal, etc.)
|
|
117
|
+
* @returns Beautified code and Source Map (null for non-JS/TS)
|
|
118
|
+
*/
|
|
119
|
+
export declare function ensureBeautified(originalPath: string, options?: BeautifyOptions): Promise<BeautifyResult>;
|
|
120
|
+
//# sourceMappingURL=beautifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beautifier.d.ts","sourceRoot":"","sources":["../src/beautifier.ts"],"names":[],"mappings":"AAKA,OAAO,EAAmC,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAIhG,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,6DAA6D;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,kBAAkB;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,YAAY,EAAE,OAAO,CAAC;CACvB;AA4BD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,cAAc,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,CAU9D;AAiBD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,aAAa,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,0EAA0E;IAC1E,eAAe,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CA2CtF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,CAQpF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAuDpD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA8CnD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,iBAAiB,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CA4BzC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,cAAc,CAAC,CAyJzB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* smart-fs - Smart file processing library
|
|
3
|
+
*
|
|
4
|
+
* Provides code beautification, truncation, search, analysis, and transformation
|
|
5
|
+
* with multi-language support and source map generation.
|
|
6
|
+
*
|
|
7
|
+
* @module smart-fs
|
|
8
|
+
*/
|
|
9
|
+
export * from './types.js';
|
|
10
|
+
export { type SupportedLanguage, type LanguageInfo, detectLanguage, getLanguageInfo, isFullySupportedLanguage, getSupportedExtensions, isExtensionSupported, } from './languageDetector.js';
|
|
11
|
+
export { type SourceMap, type BeautifyOptions, type BeautifyResult, type LocalPaths, type LocalCacheCheck, ensureBeautified, beautifyCode, beautifyJson, beautifyHtml, beautifyCss, getLocalPaths, isLocalCacheValid, } from './beautifier.js';
|
|
12
|
+
export { type TruncateOptions, type TruncateResult, truncateCode, truncateCodeFromFile, truncateFallback, truncateLongLines, truncateCodeHighPerf, } from './truncator.js';
|
|
13
|
+
export { type OriginalPosition as SearchOriginalPosition, type ContextLine, type SearchMatch, type SearchOptions, type SearchResult, searchInCode, formatSearchResult, formatSourcePosition as formatSearchSourcePosition, createRegex, escapeRegex, unescapeBackslashes, } from './searcher.js';
|
|
14
|
+
export { type OriginalPosition as AnalyzeOriginalPosition, type LocationInfo, type BindingInfo, type AnalysisResult, type AnalyzeOptions, analyzeBindings, formatAnalysisResult, formatSourcePosition as formatAnalyzeSourcePosition, parseCode, } from './analyzer.js';
|
|
15
|
+
export { type TransformOptions, type TransformResult, type OutputPaths, type BabelPluginFunction, applyCustomTransform, loadBabelPlugin, runBabelTransform, getOutputPaths, cleanBasename, } from './transformer.js';
|
|
16
|
+
import type { SmartReadOptions, ProcessingResult } from './types.js';
|
|
17
|
+
import type { SearchOptions, SearchResult } from './searcher.js';
|
|
18
|
+
import type { AnalyzeOptions, AnalysisResult } from './analyzer.js';
|
|
19
|
+
/**
|
|
20
|
+
* Smart read file with beautification and truncation
|
|
21
|
+
*
|
|
22
|
+
* This is a convenience function that combines beautification and truncation
|
|
23
|
+
* into a single operation. It handles:
|
|
24
|
+
* - Language detection (or uses specified language)
|
|
25
|
+
* - Code beautification (for supported languages)
|
|
26
|
+
* - String/line truncation
|
|
27
|
+
* - Optional line range extraction
|
|
28
|
+
*
|
|
29
|
+
* @param filePath - Path to the file to read
|
|
30
|
+
* @param options - Processing options
|
|
31
|
+
* @returns ProcessingResult with processed code and metadata
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Read and process entire file
|
|
36
|
+
* const result = await smartRead('./src/app.js');
|
|
37
|
+
*
|
|
38
|
+
* // Read specific lines with custom options
|
|
39
|
+
* const result = await smartRead('./src/app.js', {
|
|
40
|
+
* startLine: 10,
|
|
41
|
+
* endLine: 50,
|
|
42
|
+
* charLimit: 200,
|
|
43
|
+
* maxLineChars: 400
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function smartRead(filePath: string, options?: SmartReadOptions): Promise<ProcessingResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Smart search in file with beautification and source map support
|
|
50
|
+
*
|
|
51
|
+
* This function beautifies the file first, then searches in the beautified code.
|
|
52
|
+
* Results include original file positions via source map for setting breakpoints.
|
|
53
|
+
*
|
|
54
|
+
* @param filePath - Path to the file to search
|
|
55
|
+
* @param query - Search query (text or regex pattern)
|
|
56
|
+
* @param options - Search options
|
|
57
|
+
* @returns SearchResult with matches and original positions
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Simple text search
|
|
62
|
+
* const result = await smartSearch('./src/app.js', 'function');
|
|
63
|
+
*
|
|
64
|
+
* // Regex search with options
|
|
65
|
+
* const result = await smartSearch('./src/app.js', 'function\\s+\\w+', {
|
|
66
|
+
* isRegex: true,
|
|
67
|
+
* caseSensitive: true,
|
|
68
|
+
* contextLines: 3
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function smartSearch(filePath: string, query: string, options?: SearchOptions): Promise<SearchResult & {
|
|
73
|
+
formatted: string;
|
|
74
|
+
error?: string;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Find variable/function usage in file
|
|
78
|
+
*
|
|
79
|
+
* This function analyzes the code to find all bindings (definitions and references)
|
|
80
|
+
* for a specific identifier. Results include original file positions via source map.
|
|
81
|
+
*
|
|
82
|
+
* @param filePath - Path to the file to analyze
|
|
83
|
+
* @param identifier - Variable or function name to find
|
|
84
|
+
* @param options - Analysis options
|
|
85
|
+
* @returns AnalysisResult with bindings and original positions
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Find all usages of 'myFunction'
|
|
90
|
+
* const result = await findUsage('./src/app.js', 'myFunction');
|
|
91
|
+
*
|
|
92
|
+
* // Find usage at specific line
|
|
93
|
+
* const result = await findUsage('./src/app.js', 'data', {
|
|
94
|
+
* targetLine: 42
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function findUsage(filePath: string, identifier: string, options?: AnalyzeOptions): Promise<AnalysisResult & {
|
|
99
|
+
formatted: string;
|
|
100
|
+
error?: string;
|
|
101
|
+
}>;
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,cAAc,YAAY,CAAC;AAG3B,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,KAAK,gBAAgB,IAAI,sBAAsB,EAC/C,KAAK,WAAW,EAChB,KAAK,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