@diffmind/core-native 0.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/Cargo.toml ADDED
@@ -0,0 +1,17 @@
1
+ [package]
2
+ name = "core-native"
3
+ version = "0.4.0"
4
+ edition = "2021"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib"]
8
+
9
+ [dependencies]
10
+ napi = { version = "2.12.2", features = ["async", "serde-json"] }
11
+ napi-derive = "2.12.2"
12
+ core-engine = { path = "../core-engine" }
13
+ serde = { workspace = true }
14
+ serde_json = { workspace = true }
15
+
16
+ [build-dependencies]
17
+ napi-build = "2.0.1"
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Diffmind Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Binary file
package/index.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export declare class ReviewAnalyzer {
7
+ constructor(modelBytes: Buffer, tokenizerBytes: Buffer)
8
+ /**
9
+ * Analyzes a diff in chunks.
10
+ *
11
+ * # Safety
12
+ *
13
+ * This method is marked unsafe because it is an async N-API method that takes `&mut self`.
14
+ * The caller must ensure that this method is not called concurrently on the same instance
15
+ * from the JavaScript thread, as `napi-rs` cannot statically guarantee mutable access across
16
+ * the async bridge.
17
+ */
18
+ analyzeDiffChunked(diff: string, context: string, maxTokensPerChunk: number): Promise<string>
19
+ }
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ const { existsSync } = require('fs');
2
+ const { join } = require('path');
3
+
4
+ const bindingPath = join(__dirname, 'core_native.node');
5
+
6
+ if (!existsSync(bindingPath)) {
7
+ console.error(`Native binding not found at ${bindingPath}`);
8
+ process.exit(1);
9
+ }
10
+
11
+ try {
12
+ const binding = require(bindingPath);
13
+ module.exports = binding;
14
+ } catch (e) {
15
+ throw new Error(`Failed to load native binding: ${e.message}`);
16
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@diffmind/core-native",
3
+ "version": "0.4.0",
4
+ "description": "Native Node.js addon for diffmind AI engine",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "napi": {
8
+ "name": "core_native",
9
+ "package": {
10
+ "name": "@diffmind/core-native"
11
+ }
12
+ },
13
+ "devDependencies": {
14
+ "@napi-rs/cli": "^2.18.4"
15
+ },
16
+ "scripts": {
17
+ "build": "napi build --release --js index.js",
18
+ "build:debug": "napi build --js index.js",
19
+ "test": "node index.js"
20
+ }
21
+ }
package/src/lib.rs ADDED
@@ -0,0 +1,46 @@
1
+ //! diffmind core-native
2
+ //!
3
+ //! Native Node.js bindings for the shared diffmind engine.
4
+
5
+ use core_engine::ReviewAnalyzer as InnerAnalyzer;
6
+ use napi_derive::napi;
7
+
8
+ #[napi]
9
+ pub struct ReviewAnalyzer {
10
+ inner: InnerAnalyzer,
11
+ }
12
+
13
+ #[napi]
14
+ impl ReviewAnalyzer {
15
+ #[napi(constructor)]
16
+ pub fn new(model_bytes: napi::bindgen_prelude::Buffer, tokenizer_bytes: napi::bindgen_prelude::Buffer) -> napi::Result<Self> {
17
+ let inner = InnerAnalyzer::new(&model_bytes, &tokenizer_bytes)
18
+ .map_err(|e| napi::Error::from_reason(e.to_string()))?;
19
+
20
+ Ok(ReviewAnalyzer { inner })
21
+ }
22
+
23
+ /// Analyzes a diff in chunks.
24
+ ///
25
+ /// # Safety
26
+ ///
27
+ /// This method is marked unsafe because it is an async N-API method that takes `&mut self`.
28
+ /// The caller must ensure that this method is not called concurrently on the same instance
29
+ /// from the JavaScript thread, as `napi-rs` cannot statically guarantee mutable access across
30
+ /// the async bridge.
31
+ #[napi]
32
+ pub async unsafe fn analyze_diff_chunked(
33
+ &mut self,
34
+ diff: String,
35
+ context: String,
36
+ max_tokens_per_chunk: u32,
37
+ ) -> napi::Result<String> {
38
+ let findings = self
39
+ .inner
40
+ .analyze_diff_chunked(&diff, &context, max_tokens_per_chunk)
41
+ .map_err(|e| napi::Error::from_reason(e.to_string()))?;
42
+
43
+ serde_json::to_string(&findings)
44
+ .map_err(|e| napi::Error::from_reason(format!("failed to serialize findings: {e}")))
45
+ }
46
+ }