sdl-mcp-native 0.7.1

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 (3) hide show
  1. package/index.d.ts +120 -0
  2. package/index.js +146 -0
  3. package/package.json +44 -0
package/index.d.ts ADDED
@@ -0,0 +1,120 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ /** Input file descriptor passed from TypeScript to Rust. */
7
+ export interface NativeFileInput {
8
+ /** Relative path from repo root (forward slashes). */
9
+ relPath: string
10
+ /** Absolute path on disk. */
11
+ absolutePath: string
12
+ /** Repository identifier. */
13
+ repoId: string
14
+ /** Language identifier (e.g., "ts", "tsx", "js", "py", "go"). */
15
+ language: string
16
+ }
17
+ /** Range within a source file (1-indexed lines, 0-indexed columns). */
18
+ export interface NativeRange {
19
+ startLine: number
20
+ startCol: number
21
+ endLine: number
22
+ endCol: number
23
+ }
24
+ /** Extracted symbol from AST analysis. */
25
+ export interface NativeParsedSymbol {
26
+ /** Stable symbol ID: sha256("{repoId}:{relPath}:{kind}:{name}:{astFingerprint}"). */
27
+ symbolId: string
28
+ /** AST fingerprint hash. */
29
+ astFingerprint: string
30
+ /**
31
+ * Symbol kind: "function", "class", "interface", "type_alias", "method",
32
+ * "constructor", "variable", "module", "enum", "property".
33
+ */
34
+ kind: string
35
+ /** Symbol name. */
36
+ name: string
37
+ /** Whether the symbol is exported. */
38
+ exported: boolean
39
+ /** Visibility: "public", "private", "protected", "internal", or empty. */
40
+ visibility: string
41
+ /** Source range. */
42
+ range: NativeRange
43
+ /** JSON-encoded signature object. */
44
+ signatureJson: string
45
+ /** One-line summary from JSDoc or auto-generated. */
46
+ summary: string
47
+ /** JSON-encoded invariants array. */
48
+ invariantsJson: string
49
+ /** JSON-encoded side-effects array. */
50
+ sideEffectsJson: string
51
+ }
52
+ /** Extracted import statement. */
53
+ export interface NativeParsedImport {
54
+ /** Module specifier (e.g., "./utils.js", "lodash"). */
55
+ specifier: string
56
+ /** Whether the import is relative (starts with . or ..). */
57
+ isRelative: boolean
58
+ /** Whether the import is from an external package. */
59
+ isExternal: boolean
60
+ /** Named imports (e.g., ["foo", "bar"]). */
61
+ namedImports: Array<string>
62
+ /** Default import name, if any. */
63
+ defaultImport?: string
64
+ /** Namespace import name (e.g., "* as ns"), if any. */
65
+ namespaceImport?: string
66
+ /** Source range. */
67
+ range: NativeRange
68
+ }
69
+ /** Extracted call site. */
70
+ export interface NativeParsedCall {
71
+ /** Node ID of the caller (enclosing symbol). */
72
+ callerName: string
73
+ /** Callee identifier (e.g., "foo", "this.bar", "ns.baz"). */
74
+ calleeIdentifier: string
75
+ /**
76
+ * Call type: "direct", "method", "constructor", "super", "tagged_template",
77
+ * "optional_chain", "computed".
78
+ */
79
+ callType: string
80
+ /** Source range. */
81
+ range: NativeRange
82
+ }
83
+ /** Complete parse result for a single file. */
84
+ export interface NativeParsedFile {
85
+ /** Relative path (matches input). */
86
+ relPath: string
87
+ /** SHA-256 hex digest of file content. */
88
+ contentHash: string
89
+ /** Extracted symbols. */
90
+ symbols: Array<NativeParsedSymbol>
91
+ /** Extracted imports. */
92
+ imports: Array<NativeParsedImport>
93
+ /** Extracted calls. */
94
+ calls: Array<NativeParsedCall>
95
+ /** Parse error message, if any. */
96
+ parseError?: string
97
+ }
98
+ /**
99
+ * Parse and extract symbols/imports/calls from a batch of files.
100
+ *
101
+ * This is the primary entry point called from TypeScript.
102
+ * Uses Rayon for parallel processing across files.
103
+ *
104
+ * Returns NativeParsedFile[] with per-file results.
105
+ */
106
+ export declare function parseFiles(files: Array<NativeFileInput>, threadCount: number): Array<NativeParsedFile>
107
+ /**
108
+ * SHA-256 hash of a string, returned as lowercase hex.
109
+ *
110
+ * Exact parity with TypeScript `hashContent()` in `util/hashing.ts`.
111
+ * Exported for cross-validation in parity tests.
112
+ */
113
+ export declare function hashContentNative(content: string): string
114
+ /**
115
+ * Generate a stable symbol ID.
116
+ *
117
+ * Exact parity with TypeScript `generateSymbolId()` in `util/hashing.ts`.
118
+ * Exported for cross-validation in parity tests.
119
+ */
120
+ export declare function generateSymbolIdNative(repoId: string, relPath: string, kind: string, name: string, fingerprint: string): string
package/index.js ADDED
@@ -0,0 +1,146 @@
1
+ /* eslint-disable */
2
+
3
+ /**
4
+ * Platform-detection loader for sdl-mcp-native.
5
+ *
6
+ * Standard napi-rs pattern: detects process.platform/process.arch and loads
7
+ * the correct prebuilt binary from per-platform npm packages.
8
+ */
9
+
10
+ const { existsSync, readFileSync } = require("fs");
11
+ const { join } = require("path");
12
+
13
+ /**
14
+ * Determine the platform package name based on current OS/arch/libc.
15
+ * @returns {string | null}
16
+ */
17
+ function getPackageName() {
18
+ const platform = process.platform;
19
+ const arch = process.arch;
20
+
21
+ if (platform === "win32" && arch === "x64") {
22
+ return "sdl-mcp-native-win32-x64-msvc";
23
+ }
24
+ if (platform === "darwin" && arch === "x64") {
25
+ return "sdl-mcp-native-darwin-x64";
26
+ }
27
+ if (platform === "darwin" && arch === "arm64") {
28
+ return "sdl-mcp-native-darwin-arm64";
29
+ }
30
+ if (platform === "linux" && arch === "x64") {
31
+ // Detect musl vs glibc
32
+ if (isMusl()) {
33
+ return "sdl-mcp-native-linux-x64-musl";
34
+ }
35
+ return "sdl-mcp-native-linux-x64-gnu";
36
+ }
37
+ if (platform === "linux" && arch === "arm64") {
38
+ return "sdl-mcp-native-linux-arm64-gnu";
39
+ }
40
+
41
+ return null;
42
+ }
43
+
44
+ /**
45
+ * Detect musl libc on Linux.
46
+ * @returns {boolean}
47
+ */
48
+ function isMusl() {
49
+ // Check if we're running on Alpine or musl-based distro
50
+ try {
51
+ const output = readFileSync("/usr/bin/ldd", "utf8");
52
+ if (output.includes("musl")) return true;
53
+ } catch {
54
+ // ldd not readable
55
+ }
56
+
57
+ try {
58
+ if (existsSync("/etc/alpine-release")) return true;
59
+ } catch {
60
+ // not alpine
61
+ }
62
+
63
+ // Check the dynamic linker
64
+ try {
65
+ const maps = readFileSync("/proc/self/maps", "utf8");
66
+ if (maps.includes("musl")) return true;
67
+ } catch {
68
+ // /proc not available
69
+ }
70
+
71
+ return false;
72
+ }
73
+
74
+ /**
75
+ * Map platform package names to their .node file suffix.
76
+ */
77
+ const PLATFORM_NODE_FILES = {
78
+ "sdl-mcp-native-win32-x64-msvc": "sdl-mcp-native.win32-x64-msvc.node",
79
+ "sdl-mcp-native-darwin-x64": "sdl-mcp-native.darwin-x64.node",
80
+ "sdl-mcp-native-darwin-arm64": "sdl-mcp-native.darwin-arm64.node",
81
+ "sdl-mcp-native-linux-x64-gnu": "sdl-mcp-native.linux-x64-gnu.node",
82
+ "sdl-mcp-native-linux-x64-musl": "sdl-mcp-native.linux-x64-musl.node",
83
+ "sdl-mcp-native-linux-arm64-gnu": "sdl-mcp-native.linux-arm64-gnu.node",
84
+ };
85
+
86
+ let nativeBinding = null;
87
+ let loadError = null;
88
+
89
+ const packageName = getPackageName();
90
+
91
+ if (packageName) {
92
+ const nodeFileName = PLATFORM_NODE_FILES[packageName];
93
+
94
+ // 1. Try local platform-suffixed .node file (dev builds via napi artifacts)
95
+ const localPlatformPath = join(__dirname, nodeFileName);
96
+ if (existsSync(localPlatformPath)) {
97
+ try {
98
+ nativeBinding = require(localPlatformPath);
99
+ } catch (e) {
100
+ loadError = e;
101
+ }
102
+ }
103
+
104
+ // 2. Try per-platform npm package
105
+ if (!nativeBinding) {
106
+ try {
107
+ nativeBinding = require(packageName);
108
+ } catch (e) {
109
+ loadError = e;
110
+ }
111
+ }
112
+
113
+ // 3. Try legacy local files (backward compat with dev builds)
114
+ if (!nativeBinding) {
115
+ const legacyPaths = [
116
+ join(__dirname, "sdl-mcp-native.node"),
117
+ join(__dirname, "index.node"),
118
+ ];
119
+ for (const p of legacyPaths) {
120
+ if (existsSync(p)) {
121
+ try {
122
+ nativeBinding = require(p);
123
+ break;
124
+ } catch (e) {
125
+ loadError = e;
126
+ }
127
+ }
128
+ }
129
+ }
130
+ } else {
131
+ loadError = new Error(
132
+ `Unsupported platform: ${process.platform}-${process.arch}. ` +
133
+ `sdl-mcp-native supports: win32-x64, darwin-x64, darwin-arm64, linux-x64, linux-arm64`
134
+ );
135
+ }
136
+
137
+ if (!nativeBinding) {
138
+ if (loadError) {
139
+ throw loadError;
140
+ }
141
+ throw new Error("Failed to load sdl-mcp-native native binding");
142
+ }
143
+
144
+ module.exports.parseFiles = nativeBinding.parseFiles;
145
+ module.exports.hashContentNative = nativeBinding.hashContentNative;
146
+ module.exports.generateSymbolIdNative = nativeBinding.generateSymbolIdNative;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "sdl-mcp-native",
3
+ "version": "0.7.1",
4
+ "description": "Native Rust indexer for SDL-MCP with tree-sitter parsing and Rayon parallelism",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "files": [
9
+ "index.js",
10
+ "index.d.ts"
11
+ ],
12
+ "napi": {
13
+ "name": "sdl-mcp-native",
14
+ "triples": {
15
+ "defaults": false,
16
+ "additional": [
17
+ "x86_64-pc-windows-msvc",
18
+ "x86_64-apple-darwin",
19
+ "aarch64-apple-darwin",
20
+ "x86_64-unknown-linux-gnu",
21
+ "x86_64-unknown-linux-musl",
22
+ "aarch64-unknown-linux-gnu"
23
+ ]
24
+ }
25
+ },
26
+ "scripts": {
27
+ "build": "napi build --release --cargo-cwd . --config package.json .",
28
+ "artifacts": "napi artifacts",
29
+ "version": "napi version"
30
+ },
31
+ "optionalDependencies": {
32
+ "sdl-mcp-native-win32-x64-msvc": "0.7.1",
33
+ "sdl-mcp-native-darwin-x64": "0.7.1",
34
+ "sdl-mcp-native-darwin-arm64": "0.7.1",
35
+ "sdl-mcp-native-linux-x64-gnu": "0.7.1",
36
+ "sdl-mcp-native-linux-x64-musl": "0.7.1",
37
+ "sdl-mcp-native-linux-arm64-gnu": "0.7.1"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/GlitterKill/sdl-mcp.git",
42
+ "directory": "native"
43
+ }
44
+ }