@ebowwa/quant-rust 0.1.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.
Files changed (60) hide show
  1. package/README.md +161 -0
  2. package/bun-ffi.d.ts +54 -0
  3. package/dist/index.js +576 -0
  4. package/dist/src/index.d.ts +324 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/types/index.d.ts +403 -0
  7. package/dist/types/index.d.ts.map +1 -0
  8. package/native/README.md +62 -0
  9. package/native/darwin-arm64/libquant_rust.dylib +0 -0
  10. package/package.json +70 -0
  11. package/scripts/postinstall.cjs +85 -0
  12. package/src/ffi.rs +496 -0
  13. package/src/index.ts +1073 -0
  14. package/src/indicators/ma.rs +222 -0
  15. package/src/indicators/mod.rs +18 -0
  16. package/src/indicators/momentum.rs +353 -0
  17. package/src/indicators/sr.rs +195 -0
  18. package/src/indicators/trend.rs +351 -0
  19. package/src/indicators/volatility.rs +270 -0
  20. package/src/indicators/volume.rs +213 -0
  21. package/src/lib.rs +130 -0
  22. package/src/patterns/breakout.rs +431 -0
  23. package/src/patterns/chart.rs +772 -0
  24. package/src/patterns/mod.rs +394 -0
  25. package/src/patterns/sr.rs +423 -0
  26. package/src/prediction/amm.rs +338 -0
  27. package/src/prediction/arbitrage.rs +230 -0
  28. package/src/prediction/calibration.rs +317 -0
  29. package/src/prediction/kelly.rs +232 -0
  30. package/src/prediction/lmsr.rs +194 -0
  31. package/src/prediction/mod.rs +59 -0
  32. package/src/prediction/odds.rs +229 -0
  33. package/src/prediction/pnl.rs +254 -0
  34. package/src/prediction/risk.rs +228 -0
  35. package/src/risk/beta.rs +257 -0
  36. package/src/risk/drawdown.rs +256 -0
  37. package/src/risk/leverage.rs +201 -0
  38. package/src/risk/mod.rs +388 -0
  39. package/src/risk/portfolio.rs +287 -0
  40. package/src/risk/ratios.rs +290 -0
  41. package/src/risk/sizing.rs +194 -0
  42. package/src/risk/var.rs +222 -0
  43. package/src/stats/cdf.rs +257 -0
  44. package/src/stats/correlation.rs +225 -0
  45. package/src/stats/distribution.rs +194 -0
  46. package/src/stats/hypothesis.rs +177 -0
  47. package/src/stats/matrix.rs +346 -0
  48. package/src/stats/mod.rs +257 -0
  49. package/src/stats/regression.rs +239 -0
  50. package/src/stats/rolling.rs +193 -0
  51. package/src/stats/timeseries.rs +263 -0
  52. package/src/types.rs +224 -0
  53. package/src/utils/mod.rs +215 -0
  54. package/src/utils/normalize.rs +192 -0
  55. package/src/utils/price.rs +167 -0
  56. package/src/utils/quantiles.rs +177 -0
  57. package/src/utils/returns.rs +158 -0
  58. package/src/utils/rolling.rs +97 -0
  59. package/src/utils/stats.rs +154 -0
  60. package/types/index.ts +513 -0
@@ -0,0 +1,403 @@
1
+ /**
2
+ * TypeScript type definitions for quant-rust
3
+ *
4
+ * These types mirror the Rust types in src/types.rs
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ /**
9
+ * OHLCV candlestick data
10
+ */
11
+ export interface OHLCV {
12
+ /** Unix timestamp in milliseconds */
13
+ timestamp: number;
14
+ /** Opening price */
15
+ open: number;
16
+ /** High price */
17
+ high: number;
18
+ /** Low price */
19
+ low: number;
20
+ /** Closing price */
21
+ close: number;
22
+ /** Volume */
23
+ volume: number;
24
+ }
25
+ /**
26
+ * AMM (Automated Market Maker) state for constant-product AMMs
27
+ */
28
+ export interface AMMState {
29
+ /** YES pool reserves */
30
+ pool_yes: number;
31
+ /** NO pool reserves */
32
+ pool_no: number;
33
+ /** Constant product k = pool_yes * pool_no */
34
+ k: number;
35
+ /** LP token total supply */
36
+ lp_token_supply: number;
37
+ /** Fee as decimal (e.g., 0.003 for 0.3%) */
38
+ fee: number;
39
+ }
40
+ /**
41
+ * AMM cost calculation result
42
+ */
43
+ export interface AMMCostResult {
44
+ /** Total cost to buy the shares */
45
+ cost: number;
46
+ /** Average price per share */
47
+ avg_price: number;
48
+ }
49
+ /**
50
+ * AMM price impact result
51
+ */
52
+ export interface AMMPriceImpactResult {
53
+ /** Price before the trade */
54
+ initial_price: number;
55
+ /** Price after the trade */
56
+ final_price: number;
57
+ /** Price impact as decimal (e.g., 0.01 = 1%) */
58
+ price_impact: number;
59
+ /** Price impact in basis points (1 bp = 0.01%) */
60
+ impact_bps: number;
61
+ }
62
+ /**
63
+ * LMSR (Logarithmic Market Scoring Rule) state
64
+ */
65
+ export interface LMSRState {
66
+ /** YES shares outstanding */
67
+ yes_shares: number;
68
+ /** NO shares outstanding */
69
+ no_shares: number;
70
+ /** Liquidity parameter (controls price sensitivity) */
71
+ b: number;
72
+ }
73
+ /**
74
+ * LMSR price result
75
+ */
76
+ export interface LMSRPriceResult {
77
+ /** Current YES price (0-1) */
78
+ yes_price: number;
79
+ /** Current NO price (0-1) */
80
+ no_price: number;
81
+ }
82
+ /**
83
+ * Result of Kelly criterion calculation
84
+ */
85
+ export interface KellyResult {
86
+ /** Full Kelly fraction (0-1) */
87
+ kelly_fraction: number;
88
+ /** Half Kelly fraction (more conservative) */
89
+ half_kelly: number;
90
+ /** Quarter Kelly fraction (most conservative) */
91
+ quarter_kelly: number;
92
+ /** Full bet size in currency units */
93
+ full_bet_size: number;
94
+ /** Half bet size in currency units */
95
+ half_bet_size: number;
96
+ /** Quarter bet size in currency units */
97
+ quarter_bet_size: number;
98
+ /** Expected edge (your_prob - market_price) */
99
+ edge: number;
100
+ /** Decimal odds */
101
+ odds: number;
102
+ }
103
+ /**
104
+ * A betting opportunity for multi-bet Kelly
105
+ */
106
+ export interface BetOpportunity {
107
+ /** Your estimated probability of winning */
108
+ your_prob: number;
109
+ /** Current market price */
110
+ market_price: number;
111
+ }
112
+ /**
113
+ * Value at Risk (VaR) and Expected Shortfall (CVaR) result
114
+ */
115
+ export interface VaRResult {
116
+ /** Value at Risk at the given confidence level */
117
+ var: number;
118
+ /** Conditional VaR (Expected Shortfall) */
119
+ cvar: number;
120
+ /** Confidence level used */
121
+ confidence_level: number;
122
+ }
123
+ /**
124
+ * Drawdown analysis result
125
+ */
126
+ export interface DrawdownResult {
127
+ /** Maximum drawdown (as decimal, e.g., 0.25 = 25%) */
128
+ max_drawdown: number;
129
+ /** Maximum drawdown duration in periods */
130
+ max_duration: number;
131
+ /** Current drawdown */
132
+ current_drawdown: number;
133
+ /** Recovery factor (total return / max drawdown) */
134
+ recovery_factor: number;
135
+ }
136
+ /**
137
+ * Sharpe ratio result
138
+ */
139
+ export interface SharpeResult {
140
+ /** Sharpe ratio */
141
+ sharpe_ratio: number;
142
+ /** Annualized Sharpe ratio */
143
+ annualized_sharpe: number;
144
+ /** Risk-free rate used */
145
+ risk_free_rate: number;
146
+ /** Average return */
147
+ avg_return: number;
148
+ /** Standard deviation of returns */
149
+ std_dev: number;
150
+ }
151
+ /**
152
+ * Linear regression result
153
+ */
154
+ export interface RegressionResult {
155
+ /** Slope (beta coefficient) */
156
+ slope: number;
157
+ /** Intercept (alpha) */
158
+ intercept: number;
159
+ /** R-squared (coefficient of determination) */
160
+ r_squared: number;
161
+ /** Standard error of the slope */
162
+ std_error: number;
163
+ /** Number of observations */
164
+ n: number;
165
+ }
166
+ /**
167
+ * Distribution statistics
168
+ */
169
+ export interface DistributionStats {
170
+ /** Mean */
171
+ mean: number;
172
+ /** Median */
173
+ median: number;
174
+ /** Standard deviation */
175
+ std_dev: number;
176
+ /** Variance */
177
+ variance: number;
178
+ /** Skewness (asymmetry measure) */
179
+ skewness: number;
180
+ /** Kurtosis (tail heaviness, excess over normal) */
181
+ kurtosis: number;
182
+ /** Minimum value */
183
+ min: number;
184
+ /** Maximum value */
185
+ max: number;
186
+ /** Sample size */
187
+ count: number;
188
+ }
189
+ /**
190
+ * Autocorrelation result
191
+ */
192
+ export interface AutocorrelationResult {
193
+ /** Lag values */
194
+ lags: number[];
195
+ /** Autocorrelation coefficients */
196
+ autocorrelations: number[];
197
+ /** Confidence level (typically 1.96 / sqrt(n) for 95%) */
198
+ confidence_bound: number;
199
+ }
200
+ /**
201
+ * Trading signal
202
+ */
203
+ export declare const enum Signal {
204
+ /** Strong buy signal */
205
+ StrongBuy = 2,
206
+ /** Buy signal */
207
+ Buy = 1,
208
+ /** Neutral / hold */
209
+ Neutral = 0,
210
+ /** Sell signal */
211
+ Sell = -1,
212
+ /** Strong sell signal */
213
+ StrongSell = -2
214
+ }
215
+ /**
216
+ * Indicator result with value and signal
217
+ */
218
+ export interface IndicatorResult {
219
+ /** The indicator value */
220
+ value: number;
221
+ /** Trading signal derived from the indicator */
222
+ signal: Signal;
223
+ /** Optional upper band (for Bollinger, etc.) */
224
+ upper_band?: number;
225
+ /** Optional lower band */
226
+ lower_band?: number;
227
+ }
228
+ /**
229
+ * Candlestick pattern type
230
+ */
231
+ export declare const enum CandlePattern {
232
+ /** Doji - indecision */
233
+ Doji = "Doji",
234
+ /** Hammer - bullish reversal */
235
+ Hammer = "Hammer",
236
+ /** Inverted hammer - bullish reversal */
237
+ InvertedHammer = "InvertedHammer",
238
+ /** Bullish engulfing - strong bullish reversal */
239
+ BullishEngulfing = "BullishEngulfing",
240
+ /** Bearish engulfing - strong bearish reversal */
241
+ BearishEngulfing = "BearishEngulfing",
242
+ /** Morning star - bullish reversal */
243
+ MorningStar = "MorningStar",
244
+ /** Evening star - bearish reversal */
245
+ EveningStar = "EveningStar",
246
+ /** Three white soldiers - strong bullish */
247
+ ThreeWhiteSoldiers = "ThreeWhiteSoldiers",
248
+ /** Three black crows - strong bearish */
249
+ ThreeBlackCrows = "ThreeBlackCrows",
250
+ /** Shooting star - bearish reversal */
251
+ ShootingStar = "ShootingStar",
252
+ /** Hanging man - bearish reversal */
253
+ HangingMan = "HangingMan"
254
+ }
255
+ /**
256
+ * Pattern recognition result
257
+ */
258
+ export interface PatternResult {
259
+ /** The detected pattern */
260
+ pattern: CandlePattern;
261
+ /** Confidence level (0-1) */
262
+ confidence: number;
263
+ /** Index in the data where pattern was found */
264
+ index: number;
265
+ /** Whether the pattern is bullish */
266
+ is_bullish: boolean;
267
+ }
268
+ /**
269
+ * Odds conversion result
270
+ */
271
+ export interface OddsConversion {
272
+ /** Probability (0-1) */
273
+ probability: number;
274
+ /** Decimal odds (e.g., 2.0 for even money) */
275
+ decimal_odds: number;
276
+ /** American odds (e.g., -110, +200) */
277
+ american_odds: number;
278
+ }
279
+ /**
280
+ * Arbitrage detection result
281
+ */
282
+ export interface ArbitrageResult {
283
+ /** Whether an arbitrage opportunity exists */
284
+ has_arbitrage: boolean;
285
+ /** YES share price */
286
+ yes_price: number;
287
+ /** NO share price */
288
+ no_price: number;
289
+ /** Sum of prices (if < 1, arbitrage exists) */
290
+ total_price: number;
291
+ /** Profit per share if arbitrage exists */
292
+ profit_per_share: number;
293
+ /** Profit in basis points */
294
+ profit_bps: number;
295
+ }
296
+ /**
297
+ * Brier score result
298
+ */
299
+ export interface BrierScore {
300
+ /** The Brier score (lower is better, 0 = perfect) */
301
+ score: number;
302
+ /** Number of predictions evaluated */
303
+ count: number;
304
+ }
305
+ /**
306
+ * Prediction for Brier score calculation
307
+ */
308
+ export interface Prediction {
309
+ /** Predicted probability (0-1) */
310
+ predicted: number;
311
+ /** Actual outcome (0 or 1) */
312
+ actual: number;
313
+ }
314
+ /**
315
+ * MACD (Moving Average Convergence Divergence) result
316
+ */
317
+ export interface MACDResult {
318
+ /** MACD line (fast EMA - slow EMA) */
319
+ macd: number[];
320
+ /** Signal line (EMA of MACD) */
321
+ signal: number[];
322
+ /** Histogram (MACD - Signal) */
323
+ histogram: number[];
324
+ }
325
+ /**
326
+ * Stochastic Oscillator result
327
+ */
328
+ export interface StochasticResult {
329
+ /** %K line (fast stochastic) */
330
+ k: number[];
331
+ /** %D line (SMA of %K) */
332
+ d: number[];
333
+ }
334
+ /**
335
+ * Bollinger Bands result
336
+ */
337
+ export interface BollingerBandsResult {
338
+ /** Upper band */
339
+ upper: number[];
340
+ /** Middle band (SMA) */
341
+ middle: number[];
342
+ /** Lower band */
343
+ lower: number[];
344
+ /** Bandwidth ((upper - lower) / middle * 100) */
345
+ bandwidth: number[];
346
+ /** %B (position within bands) */
347
+ percent_b: number[];
348
+ }
349
+ /**
350
+ * ATR (Average True Range) result
351
+ */
352
+ export interface ATRResult {
353
+ /** ATR values */
354
+ atr: number[];
355
+ /** True Range values */
356
+ tr: number[];
357
+ }
358
+ /**
359
+ * Keltner Channels result
360
+ */
361
+ export interface KeltnerChannelsResult {
362
+ /** Upper channel */
363
+ upper: number[];
364
+ /** Middle channel (EMA) */
365
+ middle: number[];
366
+ /** Lower channel */
367
+ lower: number[];
368
+ }
369
+ /**
370
+ * Edge calculation result
371
+ */
372
+ export interface EdgeResult {
373
+ /** Your edge (your_probability - market_price) */
374
+ edge: number;
375
+ /** Whether you have a positive edge */
376
+ has_edge: boolean;
377
+ /** Edge as percentage */
378
+ edge_percent: number;
379
+ }
380
+ /**
381
+ * Calculate your edge in a prediction market bet
382
+ */
383
+ export declare function calculateEdge(yourProbability: number, marketPrice: number): EdgeResult;
384
+ /**
385
+ * Fixed fractional position sizing result
386
+ */
387
+ export interface PositionSizeResult {
388
+ /** Position size in currency units */
389
+ position_size: number;
390
+ /** Number of shares/contracts */
391
+ shares: number;
392
+ /** Risk amount in currency units */
393
+ risk_amount: number;
394
+ /** Entry price */
395
+ entry_price: number;
396
+ /** Stop loss price */
397
+ stop_loss: number;
398
+ }
399
+ /**
400
+ * Calculate position size using fixed fractional risk management
401
+ */
402
+ export declare function positionSizeFixedFractional(capital: number, riskPercent: number, entryPrice: number, stopLoss: number): PositionSizeResult;
403
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,oBAAoB;I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WAAW,EAAE,MAAM,GAClB,UAAU,CAOZ;AAMD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,kBAAkB,CAapB"}
@@ -0,0 +1,62 @@
1
+ # Native Binaries
2
+
3
+ This directory contains prebuilt native binaries for the `@ebowwa/quant-rust` package.
4
+
5
+ ## Directory Structure
6
+
7
+ ```
8
+ native/
9
+ ├── darwin-x64/ # macOS (Intel)
10
+ │ └── libquant_rust.dylib
11
+ ├── darwin-arm64/ # macOS (Apple Silicon)
12
+ │ └── libquant_rust.dylib
13
+ ├── linux-x64/ # Linux (x86_64)
14
+ │ └── libquant_rust.so
15
+ └── win32-x64/ # Windows (x86_64)
16
+ └── quant_rust.dll
17
+ ```
18
+
19
+ ## Building from Source
20
+
21
+ If a prebuilt binary is not available for your platform, you can build from source:
22
+
23
+ ```bash
24
+ # Navigate to the package directory
25
+ cd node_modules/@ebowwa/quant-rust
26
+
27
+ # Build with Cargo
28
+ cargo build --release
29
+ ```
30
+
31
+ The compiled library will be placed in `target/release/`.
32
+
33
+ ## Supported Platforms
34
+
35
+ | Platform | Architecture | Binary Name |
36
+ |----------|--------------|-------------|
37
+ | macOS | x64 (Intel) | libquant_rust.dylib |
38
+ | macOS | arm64 (Apple Silicon) | libquant_rust.dylib |
39
+ | Linux | x64 | libquant_rust.so |
40
+ | Windows | x64 | quant_rust.dll |
41
+
42
+ ## Adding Prebuilt Binaries
43
+
44
+ To add prebuilt binaries for distribution:
45
+
46
+ 1. Build the library on the target platform:
47
+ ```bash
48
+ cargo build --release
49
+ ```
50
+
51
+ 2. Copy the binary to the appropriate directory:
52
+ ```bash
53
+ cp target/release/libquant_rust.dylib native/darwin-arm64/
54
+ ```
55
+
56
+ 3. The postinstall script will automatically detect and use the correct binary.
57
+
58
+ ## Binary Requirements
59
+
60
+ - Rust 1.70 or later
61
+ - Target platform toolchain
62
+ - For cross-compilation, see the Rust cross-compilation documentation
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@ebowwa/quant-rust",
3
+ "version": "0.1.0",
4
+ "description": "High-performance quantitative finance library with Rust FFI bindings for Bun",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/src/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "native",
19
+ "src",
20
+ "types",
21
+ "scripts",
22
+ "bun-ffi.d.ts"
23
+ ],
24
+ "scripts": {
25
+ "build": "bun run build:rust && bun run build:ts",
26
+ "build:rust": "cargo build --release",
27
+ "build:ts": "bun build ./src/index.ts --outdir ./dist --target=bun && tsc --emitDeclarationOnly --declaration --outDir ./dist",
28
+ "build:ts-only": "bun build ./src/index.ts --outdir ./dist --target=bun",
29
+ "build:types": "tsc --emitDeclarationOnly --declaration --outDir ./dist",
30
+ "prepublishOnly": "bun run build",
31
+ "postinstall": "node scripts/postinstall.cjs",
32
+ "test": "bun test",
33
+ "clean": "rm -rf dist && cargo clean"
34
+ },
35
+ "keywords": [
36
+ "quant",
37
+ "finance",
38
+ "trading",
39
+ "prediction-markets",
40
+ "kelly-criterion",
41
+ "amm",
42
+ "technical-indicators",
43
+ "rust",
44
+ "ffi",
45
+ "bun"
46
+ ],
47
+ "author": "ebowwa",
48
+ "license": "MIT",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/ebowwa/codespaces",
52
+ "directory": "packages/src/quant-rust"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/ebowwa/codespaces/issues"
56
+ },
57
+ "homepage": "https://github.com/ebowwa/codespaces/tree/main/packages/src/quant-rust#readme",
58
+ "engines": {
59
+ "bun": ">=1.0.0"
60
+ },
61
+ "dependencies": {},
62
+ "devDependencies": {
63
+ "bun-types": "^1.3.9",
64
+ "typescript": "^5.9.3"
65
+ },
66
+ "publishConfig": {
67
+ "access": "public",
68
+ "registry": "https://registry.npmjs.org"
69
+ }
70
+ }
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for @ebowwa/quant-rust
5
+ *
6
+ * This script copies the appropriate native binary based on the current platform.
7
+ * It's designed to work with prebuilt binaries in the native/ directory.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ // Platform detection
14
+ const platform = process.platform;
15
+ const arch = process.arch;
16
+
17
+ // Map to our naming convention
18
+ const platformMap = {
19
+ darwin: 'darwin',
20
+ linux: 'linux',
21
+ win32: 'win32',
22
+ };
23
+
24
+ const archMap = {
25
+ x64: 'x64',
26
+ arm64: 'arm64',
27
+ ia32: 'x86',
28
+ };
29
+
30
+ // Library names per platform
31
+ const libNames = {
32
+ darwin: 'libquant_rust.dylib',
33
+ linux: 'libquant_rust.so',
34
+ win32: 'quant_rust.dll',
35
+ };
36
+
37
+ function getNativeDir() {
38
+ const mappedPlatform = platformMap[platform];
39
+ const mappedArch = archMap[arch];
40
+
41
+ if (!mappedPlatform || !mappedArch) {
42
+ console.warn(`@ebowwa/quant-rust: Unsupported platform ${platform}-${arch}`);
43
+ console.warn('You may need to build from source: cargo build --release');
44
+ return null;
45
+ }
46
+
47
+ return path.join(__dirname, '..', 'native', `${mappedPlatform}-${mappedArch}`);
48
+ }
49
+
50
+ function main() {
51
+ console.log('@ebowwa/quant-rust: Setting up native binary...');
52
+
53
+ const nativeDir = getNativeDir();
54
+ if (!nativeDir) {
55
+ process.exit(0); // Non-fatal, just warn
56
+ }
57
+
58
+ const libName = libNames[platform];
59
+ const sourcePath = path.join(nativeDir, libName);
60
+
61
+ // Check if prebuilt binary exists
62
+ if (fs.existsSync(sourcePath)) {
63
+ console.log(`@ebowwa/quant-rust: Found prebuilt binary at ${sourcePath}`);
64
+ return;
65
+ }
66
+
67
+ // Check for development build
68
+ const releasePath = path.join(__dirname, '..', 'target', 'release', libName);
69
+ if (fs.existsSync(releasePath)) {
70
+ console.log(`@ebowwa/quant-rust: Found development build at ${releasePath}`);
71
+ return;
72
+ }
73
+
74
+ // No binary found
75
+ console.warn(`@ebowwa/quant-rust: Native binary not found for ${platform}-${arch}`);
76
+ console.warn('');
77
+ console.warn('To build from source:');
78
+ console.warn(' cd node_modules/@ebowwa/quant-rust');
79
+ console.warn(' cargo build --release');
80
+ console.warn('');
81
+ console.warn('Or download prebuilt binaries from:');
82
+ console.warn(' https://github.com/ebowwa/codespaces/releases');
83
+ }
84
+
85
+ main();