@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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Tool definition interface for MCP tools.
|
|
4
|
+
* Each tool has a name, description, schema (Zod raw shape), and async handler.
|
|
5
|
+
*/
|
|
6
|
+
export interface ToolDefinition<TSchema extends z.ZodRawShape = z.ZodRawShape> {
|
|
7
|
+
/** Unique tool name (e.g., 'read_code_smart') */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Human-readable description of what the tool does */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Zod schema object defining input parameters */
|
|
12
|
+
schema: TSchema;
|
|
13
|
+
/** Async handler function that processes the tool request */
|
|
14
|
+
handler: (params: z.infer<z.ZodObject<TSchema>>) => Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to create a type-safe tool definition.
|
|
18
|
+
* Validates the tool definition structure at compile time.
|
|
19
|
+
*
|
|
20
|
+
* @param definition - The tool definition object
|
|
21
|
+
* @returns The same definition with proper typing
|
|
22
|
+
*/
|
|
23
|
+
export declare function defineTool<TSchema extends z.ZodRawShape>(definition: ToolDefinition<TSchema>): ToolDefinition<TSchema>;
|
|
24
|
+
//# sourceMappingURL=ToolDefinition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolDefinition.d.ts","sourceRoot":"","sources":["../../src/tools/ToolDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW;IAC3E,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,OAAO,CAAC;IAChB,6DAA6D;IAC7D,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACrE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,WAAW,EACtD,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,GAClC,cAAc,CAAC,OAAO,CAAC,CAEzB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatted code result interface
|
|
3
|
+
*/
|
|
4
|
+
export interface FormattedCode {
|
|
5
|
+
content: string;
|
|
6
|
+
totalLines: number;
|
|
7
|
+
startLine: number;
|
|
8
|
+
endLine: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Detection type for JSVMP patterns
|
|
12
|
+
*/
|
|
13
|
+
export type DetectionType = "If-Else Dispatcher" | "Switch Dispatcher" | "Instruction Array" | "Stack Operation";
|
|
14
|
+
/**
|
|
15
|
+
* Confidence level for detection results
|
|
16
|
+
*/
|
|
17
|
+
export type ConfidenceLevel = "ultra_high" | "high" | "medium" | "low";
|
|
18
|
+
/**
|
|
19
|
+
* A detected region in the code
|
|
20
|
+
*/
|
|
21
|
+
export interface DetectionRegion {
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
type: DetectionType;
|
|
25
|
+
confidence: ConfidenceLevel;
|
|
26
|
+
description: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Complete detection result from LLM analysis
|
|
30
|
+
*/
|
|
31
|
+
export interface DetectionResult {
|
|
32
|
+
summary: string;
|
|
33
|
+
regions: DetectionRegion[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 格式化代码为 LLM 分析格式
|
|
37
|
+
* 格式: "LineNo SourceLoc Code"
|
|
38
|
+
*
|
|
39
|
+
* 处理流程:
|
|
40
|
+
* 1. 调用 ensureBeautified 美化代码
|
|
41
|
+
* 2. 调用 truncateCodeHighPerf 截断长字符串
|
|
42
|
+
* 3. 使用 SourceMapConsumer 获取原始坐标
|
|
43
|
+
* 4. 格式化为 "LineNo SourceLoc Code" 格式
|
|
44
|
+
*
|
|
45
|
+
* @param filePath - Path to the JavaScript file
|
|
46
|
+
* @param startLine - Start line number (1-based)
|
|
47
|
+
* @param endLine - End line number (1-based)
|
|
48
|
+
* @param charLimit - Character limit for string truncation (default 300)
|
|
49
|
+
* @returns FormattedCode object with formatted content and metadata
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatCodeForAnalysis(filePath: string, startLine: number, endLine: number, charLimit?: number): Promise<FormattedCode>;
|
|
52
|
+
/**
|
|
53
|
+
* Parse and validate LLM detection result from JSON string
|
|
54
|
+
*
|
|
55
|
+
* Validates:
|
|
56
|
+
* - JSON is parseable
|
|
57
|
+
* - Required fields exist: summary, regions
|
|
58
|
+
* - Each region has required fields: start, end, type, confidence, description
|
|
59
|
+
* - Enum values are valid
|
|
60
|
+
*
|
|
61
|
+
* @param jsonString - JSON string from LLM response
|
|
62
|
+
* @returns Parsed and validated DetectionResult
|
|
63
|
+
* @throws Error if JSON is invalid or structure doesn't match expected format
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseDetectionResult(jsonString: string): DetectionResult;
|
|
66
|
+
/**
|
|
67
|
+
* Input schema for ai_find_jsvmp_dispatcher tool
|
|
68
|
+
*/
|
|
69
|
+
export declare const AiFindJsvmpDispatcherInputSchema: any;
|
|
70
|
+
/**
|
|
71
|
+
* ai_find_jsvmp_dispatcher tool definition
|
|
72
|
+
*
|
|
73
|
+
* AI-powered tool that analyzes JavaScript code to find JSVMP (JavaScript Virtual Machine Protection)
|
|
74
|
+
* dispatcher patterns using LLM-based analysis. Requires OPENAI_API_KEY environment variable.
|
|
75
|
+
*
|
|
76
|
+
* Requirements: 5.1, 5.2, 1.2, 5.3
|
|
77
|
+
*/
|
|
78
|
+
export declare const aiFindJsvmpDispatcher: import("./ToolDefinition.js").ToolDefinition<any>;
|
|
79
|
+
//# sourceMappingURL=aiFindJs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|
|
1
|
+
/**
|
|
2
|
+
* Schema for apply_custom_transform tool input validation
|
|
3
|
+
*/
|
|
4
|
+
export declare const ApplyCustomTransformInputSchema: any;
|
|
5
|
+
/**
|
|
6
|
+
* apply_custom_transform tool definition
|
|
7
|
+
* Apply a custom Babel transformation to deobfuscate JavaScript code.
|
|
8
|
+
*/
|
|
9
|
+
export declare const applyCustomTransform: import("./ToolDefinition.js").ToolDefinition<{
|
|
10
|
+
target_file: any;
|
|
11
|
+
script_path: any;
|
|
12
|
+
output_suffix: any;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=applyCustomTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyCustomTransform.d.ts","sourceRoot":"","sources":["../../src/tools/applyCustomTransform.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,+BAA+B,KAI1C,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;EA+B/B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema for find_usage_smart tool input validation
|
|
3
|
+
*/
|
|
4
|
+
export declare const FindUsageSmartInputSchema: any;
|
|
5
|
+
/**
|
|
6
|
+
* find_usage_smart tool definition
|
|
7
|
+
* Find all definitions and references of a variable/function using AST scope analysis.
|
|
8
|
+
*/
|
|
9
|
+
export declare const findUsageSmart: import("./ToolDefinition.js").ToolDefinition<{
|
|
10
|
+
file_path: any;
|
|
11
|
+
identifier: any;
|
|
12
|
+
line: any;
|
|
13
|
+
char_limit: any;
|
|
14
|
+
max_line_chars: any;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=findUsageSmart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findUsageSmart.d.ts","sourceRoot":"","sources":["../../src/tools/findUsageSmart.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,eAAO,MAAM,yBAAyB,KAQpC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;;EA0DzB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool aggregation module
|
|
3
|
+
* Collects all tool definitions and exports them as a unified array.
|
|
4
|
+
*/
|
|
5
|
+
import { ApplyCustomTransformInputSchema } from './applyCustomTransform.js';
|
|
6
|
+
import { SearchCodeSmartInputSchema } from './searchCodeSmart.js';
|
|
7
|
+
import { FindUsageSmartInputSchema } from './findUsageSmart.js';
|
|
8
|
+
/**
|
|
9
|
+
* Array of all available MCP tool definitions.
|
|
10
|
+
* To add a new tool:
|
|
11
|
+
* 1. Create a new tool module in src/tools/
|
|
12
|
+
* 2. Import it here
|
|
13
|
+
* 3. Add it to this array
|
|
14
|
+
*/
|
|
15
|
+
export declare const tools: readonly [import("./ToolDefinition.js").ToolDefinition<{
|
|
16
|
+
file_path: any;
|
|
17
|
+
start_line: any;
|
|
18
|
+
end_line: any;
|
|
19
|
+
char_limit: any;
|
|
20
|
+
max_line_chars: any;
|
|
21
|
+
save_local: any;
|
|
22
|
+
}>, import("./ToolDefinition.js").ToolDefinition<{
|
|
23
|
+
target_file: any;
|
|
24
|
+
script_path: any;
|
|
25
|
+
output_suffix: any;
|
|
26
|
+
}>, import("./ToolDefinition.js").ToolDefinition<{
|
|
27
|
+
file_path: any;
|
|
28
|
+
query: any;
|
|
29
|
+
context_lines: any;
|
|
30
|
+
case_sensitive: any;
|
|
31
|
+
char_limit: any;
|
|
32
|
+
max_line_chars: any;
|
|
33
|
+
is_regex: any;
|
|
34
|
+
}>, import("./ToolDefinition.js").ToolDefinition<{
|
|
35
|
+
file_path: any;
|
|
36
|
+
identifier: any;
|
|
37
|
+
line: any;
|
|
38
|
+
char_limit: any;
|
|
39
|
+
max_line_chars: any;
|
|
40
|
+
}>, import("./ToolDefinition.js").ToolDefinition<any>];
|
|
41
|
+
export { ToolDefinition, defineTool } from './ToolDefinition.js';
|
|
42
|
+
export { ApplyCustomTransformInputSchema, SearchCodeSmartInputSchema, FindUsageSmartInputSchema };
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAwB,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAAmB,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAkB,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGhF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;sDAMR,CAAC;AAGX,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* read_code_smart tool definition
|
|
3
|
+
* Read and beautify minified/obfuscated JavaScript code with source map coordinates.
|
|
4
|
+
*/
|
|
5
|
+
export declare const readCodeSmart: import("./ToolDefinition.js").ToolDefinition<{
|
|
6
|
+
file_path: any;
|
|
7
|
+
start_line: any;
|
|
8
|
+
end_line: any;
|
|
9
|
+
char_limit: any;
|
|
10
|
+
max_line_chars: any;
|
|
11
|
+
save_local: any;
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=readCodeSmart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readCodeSmart.d.ts","sourceRoot":"","sources":["../../src/tools/readCodeSmart.ts"],"names":[],"mappings":"AA0CA;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;EAyFxB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema for search_code_smart tool input validation
|
|
3
|
+
*/
|
|
4
|
+
export declare const SearchCodeSmartInputSchema: any;
|
|
5
|
+
/**
|
|
6
|
+
* search_code_smart tool definition
|
|
7
|
+
* Search for text or regex patterns in beautified JavaScript code.
|
|
8
|
+
*/
|
|
9
|
+
export declare const searchCodeSmart: import("./ToolDefinition.js").ToolDefinition<{
|
|
10
|
+
file_path: any;
|
|
11
|
+
query: any;
|
|
12
|
+
context_lines: any;
|
|
13
|
+
case_sensitive: any;
|
|
14
|
+
char_limit: any;
|
|
15
|
+
max_line_chars: any;
|
|
16
|
+
is_regex: any;
|
|
17
|
+
}>;
|
|
18
|
+
//# sourceMappingURL=searchCodeSmart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchCodeSmart.d.ts","sourceRoot":"","sources":["../../src/tools/searchCodeSmart.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,eAAO,MAAM,0BAA0B,KAQrC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;EA0C1B,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type SourceMap } from './beautifier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Transform options interface
|
|
4
|
+
*/
|
|
5
|
+
export interface TransformOptions {
|
|
6
|
+
/** Path to the user's Babel plugin script */
|
|
7
|
+
scriptPath: string;
|
|
8
|
+
/** Output file suffix (default "_deob") */
|
|
9
|
+
outputSuffix?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Transform result interface
|
|
13
|
+
*/
|
|
14
|
+
export interface TransformResult {
|
|
15
|
+
/** Transformed code */
|
|
16
|
+
code: string;
|
|
17
|
+
/** Cascaded Source Map */
|
|
18
|
+
map: SourceMap;
|
|
19
|
+
/** Output file path */
|
|
20
|
+
outputPath: string;
|
|
21
|
+
/** Source Map file path */
|
|
22
|
+
mapPath: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Output paths interface
|
|
26
|
+
*/
|
|
27
|
+
export interface OutputPaths {
|
|
28
|
+
/** Output JS file path */
|
|
29
|
+
outputPath: string;
|
|
30
|
+
/** Source Map file path */
|
|
31
|
+
mapPath: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Clean basename by removing .beautified and _deob* suffixes
|
|
35
|
+
*
|
|
36
|
+
* Examples:
|
|
37
|
+
* - main.js -> main
|
|
38
|
+
* - main.beautified.js -> main
|
|
39
|
+
* - main_deob.js -> main
|
|
40
|
+
* - main.beautified_deob.js -> main
|
|
41
|
+
* - main_deob_v2.js -> main
|
|
42
|
+
*
|
|
43
|
+
* @param filename - Original filename (with or without path)
|
|
44
|
+
* @returns Cleaned basename without extension
|
|
45
|
+
*/
|
|
46
|
+
export declare function cleanBasename(filename: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Calculate output paths for transformed file
|
|
49
|
+
*
|
|
50
|
+
* @param targetFile - Path to the target file
|
|
51
|
+
* @param outputSuffix - Suffix for output file (default "_deob")
|
|
52
|
+
* @returns Output paths for JS and map files
|
|
53
|
+
*/
|
|
54
|
+
export declare function getOutputPaths(targetFile: string, outputSuffix?: string): OutputPaths;
|
|
55
|
+
/**
|
|
56
|
+
* Babel plugin function type
|
|
57
|
+
* A Babel plugin is a function that receives babel API and returns a visitor object
|
|
58
|
+
*/
|
|
59
|
+
export type BabelPluginFunction = (babel: {
|
|
60
|
+
types: typeof import('@babel/types');
|
|
61
|
+
}) => {
|
|
62
|
+
visitor: Record<string, unknown>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Load a Babel plugin script from the given path
|
|
66
|
+
*
|
|
67
|
+
* Features:
|
|
68
|
+
* - Resolves to absolute path
|
|
69
|
+
* - Clears require cache for hot-reloading
|
|
70
|
+
* - Validates plugin format
|
|
71
|
+
*
|
|
72
|
+
* @param scriptPath - Path to the Babel plugin script
|
|
73
|
+
* @returns The loaded Babel plugin function
|
|
74
|
+
* @throws Error if script not found or invalid format
|
|
75
|
+
*/
|
|
76
|
+
export declare function loadBabelPlugin(scriptPath: string): Promise<BabelPluginFunction>;
|
|
77
|
+
/**
|
|
78
|
+
* Babel transform result interface
|
|
79
|
+
*/
|
|
80
|
+
interface BabelTransformResult {
|
|
81
|
+
/** Transformed code */
|
|
82
|
+
code: string;
|
|
83
|
+
/** Generated source map (cascaded) */
|
|
84
|
+
map: SourceMap;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Run Babel transform with source map cascade
|
|
88
|
+
*
|
|
89
|
+
* Configuration:
|
|
90
|
+
* - inputSourceMap: Enables cascade from beautified -> original
|
|
91
|
+
* - sourceMaps: true to generate output source map
|
|
92
|
+
* - retainLines: false for best readability
|
|
93
|
+
* - compact: false for readable output
|
|
94
|
+
* - minified: false for readable output
|
|
95
|
+
*
|
|
96
|
+
* @param code - Input code (beautified)
|
|
97
|
+
* @param inputSourceMap - Source map from beautifier (beautified -> original)
|
|
98
|
+
* @param plugin - Babel plugin function
|
|
99
|
+
* @param filename - Original filename for source map
|
|
100
|
+
* @returns Transformed code and cascaded source map
|
|
101
|
+
*/
|
|
102
|
+
export declare function runBabelTransform(code: string, inputSourceMap: SourceMap, plugin: BabelPluginFunction, filename: string): BabelTransformResult;
|
|
103
|
+
/**
|
|
104
|
+
* Apply custom Babel transform to a JavaScript file
|
|
105
|
+
*
|
|
106
|
+
* Process:
|
|
107
|
+
* 1. Load and validate the Babel plugin script
|
|
108
|
+
* 2. Get beautified code and source map from target file
|
|
109
|
+
* 3. Run Babel transform with source map cascade
|
|
110
|
+
* 4. Write output file and source map
|
|
111
|
+
* 5. Append sourceMappingURL comment
|
|
112
|
+
*
|
|
113
|
+
* @param targetFile - Path to the JavaScript file to transform
|
|
114
|
+
* @param options - Transform options (scriptPath, outputSuffix)
|
|
115
|
+
* @returns Transform result with output paths
|
|
116
|
+
*/
|
|
117
|
+
export declare function applyCustomTransform(targetFile: string, options: TransformOptions): Promise<TransformResult>;
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,GAAG,EAAE,SAAS,CAAC;IACf,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,0BAA0B;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAiBtD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,GAAE,MAAgB,GAAG,WAAW,CAS9F;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,cAAc,cAAc,CAAC,CAAA;CAAE,KAAK;IACrF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAmCtF;AAGD;;GAEG;AACH,UAAU,oBAAoB;IAC5B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,GAAG,EAAE,SAAS,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,SAAS,EACzB,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,MAAM,GACf,oBAAoB,CAqCtB;AAGD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CA6D1B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type SupportedLanguage } from './languageDetector.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for truncation operations
|
|
4
|
+
*/
|
|
5
|
+
export interface TruncateOptions {
|
|
6
|
+
/** Override auto-detected language */
|
|
7
|
+
language?: SupportedLanguage;
|
|
8
|
+
/** Character limit for string truncation (default: 200) */
|
|
9
|
+
charLimit?: number;
|
|
10
|
+
/** Maximum characters per line (default: 500) */
|
|
11
|
+
maxLineChars?: number;
|
|
12
|
+
/** Preview length for truncated content (default: 50) */
|
|
13
|
+
previewLength?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Result of truncation operation
|
|
17
|
+
*/
|
|
18
|
+
export interface TruncateResult {
|
|
19
|
+
/** Truncated code */
|
|
20
|
+
code: string;
|
|
21
|
+
/** Whether fallback mode was used */
|
|
22
|
+
usedFallback: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Legacy function name for backward compatibility
|
|
26
|
+
* @deprecated Use truncateCode instead
|
|
27
|
+
*/
|
|
28
|
+
export declare function truncateCodeHighPerf(sourceCode: string, limit?: number, previewLength?: number): string;
|
|
29
|
+
/**
|
|
30
|
+
* Fallback truncation for unsupported languages
|
|
31
|
+
* Only truncates lines exceeding the character limit, no AST parsing
|
|
32
|
+
* Preserves the original line count (Requirement 3.3)
|
|
33
|
+
*
|
|
34
|
+
* @param code - Source code to process
|
|
35
|
+
* @param maxLineChars - Maximum characters per line (default: 500)
|
|
36
|
+
* @param previewLength - Length of start/end preview portions (default: 50)
|
|
37
|
+
* @returns Truncated code with preserved line count
|
|
38
|
+
*/
|
|
39
|
+
export declare function truncateFallback(code: string, maxLineChars?: number, previewLength?: number): string;
|
|
40
|
+
/**
|
|
41
|
+
* Truncate code based on language type
|
|
42
|
+
* - For JS/TS: Use AST-based truncation for string literals + line truncation
|
|
43
|
+
* - For other languages: Use line-based truncation only (fallback mode)
|
|
44
|
+
*
|
|
45
|
+
* @param code - Source code to process
|
|
46
|
+
* @param options - Truncation options including language, limits, etc.
|
|
47
|
+
* @returns TruncateResult with truncated code and fallback indicator
|
|
48
|
+
*/
|
|
49
|
+
export declare function truncateCode(code: string, options?: TruncateOptions): TruncateResult;
|
|
50
|
+
/**
|
|
51
|
+
* Truncate code from a file path, auto-detecting language
|
|
52
|
+
*
|
|
53
|
+
* @param filePath - Path to the file (used for language detection)
|
|
54
|
+
* @param code - Source code to process
|
|
55
|
+
* @param options - Truncation options (language override, limits, etc.)
|
|
56
|
+
* @returns TruncateResult with truncated code and fallback indicator
|
|
57
|
+
*/
|
|
58
|
+
export declare function truncateCodeFromFile(filePath: string, code: string, options?: Omit<TruncateOptions, 'language'> & {
|
|
59
|
+
language?: SupportedLanguage;
|
|
60
|
+
}): TruncateResult;
|
|
61
|
+
/**
|
|
62
|
+
* Truncate lines that exceed the maximum character limit
|
|
63
|
+
* @param code - Source code to process
|
|
64
|
+
* @param maxLineChars - Maximum characters per line (default 500)
|
|
65
|
+
* @param previewRatio - Ratio of line to show at start/end (default 0.2)
|
|
66
|
+
* @returns Code with truncated long lines
|
|
67
|
+
*/
|
|
68
|
+
export declare function truncateLongLines(code: string, maxLineChars?: number, previewRatio?: number): string;
|
|
69
|
+
//# sourceMappingURL=truncator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for smart-fs library
|
|
3
|
+
* @module types
|
|
4
|
+
*/
|
|
5
|
+
import type { SupportedLanguage } from './languageDetector.js';
|
|
6
|
+
import type { SourceMap } from './beautifier.js';
|
|
7
|
+
/**
|
|
8
|
+
* Options for processing files with smart-fs
|
|
9
|
+
*/
|
|
10
|
+
export interface ProcessingOptions {
|
|
11
|
+
/** Override auto-detected language */
|
|
12
|
+
language?: SupportedLanguage;
|
|
13
|
+
/** Character limit for string truncation (default: 300) */
|
|
14
|
+
charLimit?: number;
|
|
15
|
+
/** Maximum characters per line (default: 500) */
|
|
16
|
+
maxLineChars?: number;
|
|
17
|
+
/** Preview length for truncated content (default: 50) */
|
|
18
|
+
previewLength?: number;
|
|
19
|
+
/** Save beautified file locally */
|
|
20
|
+
saveLocal?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Result of processing a file
|
|
24
|
+
*/
|
|
25
|
+
export interface ProcessingResult {
|
|
26
|
+
/** Processed code */
|
|
27
|
+
code: string;
|
|
28
|
+
/** Source map (null for unsupported languages) */
|
|
29
|
+
sourceMap: SourceMap | null;
|
|
30
|
+
/** Detected or specified language */
|
|
31
|
+
language: SupportedLanguage;
|
|
32
|
+
/** Whether fallback mode was used */
|
|
33
|
+
usedFallback: boolean;
|
|
34
|
+
/** Local file path if saved */
|
|
35
|
+
localPath?: string;
|
|
36
|
+
/** Error message if any */
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Options for smartRead function
|
|
41
|
+
*/
|
|
42
|
+
export interface SmartReadOptions extends ProcessingOptions {
|
|
43
|
+
/** Starting line number (1-based, inclusive) */
|
|
44
|
+
startLine?: number;
|
|
45
|
+
/** Ending line number (1-based, inclusive) */
|
|
46
|
+
endLine?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Error codes for smart-fs operations
|
|
50
|
+
*/
|
|
51
|
+
export type ErrorCode = 'FILE_NOT_FOUND' | 'PARSE_ERROR' | 'PERMISSION_DENIED' | 'INVALID_OPTIONS';
|
|
52
|
+
/**
|
|
53
|
+
* Error result structure
|
|
54
|
+
*/
|
|
55
|
+
export interface ErrorResult {
|
|
56
|
+
success: false;
|
|
57
|
+
error: string;
|
|
58
|
+
code: ErrorCode;
|
|
59
|
+
details?: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sCAAsC;IACtC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,qCAAqC;IACrC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,qCAAqC;IACrC,YAAY,EAAE,OAAO,CAAC;IACtB,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,gBAAgB,GAChB,aAAa,GACb,mBAAmB,GACnB,iBAAiB,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reverse-craft/smart-fs",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Core file processing library for code beautification, truncation, and analysis - supports multiple languages with AST-based and fallback processing",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/
|
|
7
|
-
"
|
|
8
|
-
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
9
13
|
},
|
|
10
14
|
"scripts": {
|
|
11
15
|
"build": "node build.js",
|
|
12
16
|
"build:types": "tsc --emitDeclarationOnly",
|
|
13
|
-
"start": "node dist/server.js",
|
|
14
17
|
"test": "vitest --run",
|
|
15
18
|
"prepublishOnly": "npm run build"
|
|
16
19
|
},
|
|
17
20
|
"keywords": [
|
|
18
|
-
"mcp",
|
|
19
|
-
"model-context-protocol",
|
|
20
21
|
"javascript",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
22
|
+
"typescript",
|
|
23
|
+
"code-processing",
|
|
23
24
|
"beautifier",
|
|
25
|
+
"truncation",
|
|
24
26
|
"source-map",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
27
|
+
"ast",
|
|
28
|
+
"multi-language",
|
|
29
|
+
"file-processing"
|
|
28
30
|
],
|
|
29
31
|
"license": "MIT",
|
|
30
32
|
"repository": {
|
|
@@ -49,14 +51,12 @@
|
|
|
49
51
|
"@babel/parser": "^7.28.5",
|
|
50
52
|
"@babel/traverse": "^7.28.5",
|
|
51
53
|
"@babel/types": "^7.28.5",
|
|
52
|
-
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
53
54
|
"esbuild": "^0.27.2",
|
|
54
55
|
"estree-walker": "^3.0.3",
|
|
55
56
|
"fs-extra": "^11.3.3",
|
|
56
57
|
"magic-string": "^0.30.21",
|
|
57
58
|
"meriyah": "^7.0.0",
|
|
58
|
-
"source-map-js": "^1.2.1"
|
|
59
|
-
"zod": "^4.2.1"
|
|
59
|
+
"source-map-js": "^1.2.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/babel__core": "^7.20.5",
|