Skip to content

Commit 3c0536d

Browse files
committed
refactor: flatten worker structure by moving rust_ai_core to worker root
- Converted workspace Cargo.toml to package manifest - Moved src/, tests/, .cargo/ from rust_ai_core to worker/ - Updated package.json scripts with new paths - Updated getAIVersion.ts source file paths - Updated generate-types.sh and test-ai-comparison.sh paths - Removed redundant rust_ai_core subdirectory
1 parent 66f08cd commit 3c0536d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+68
-78
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
"lint:fix": "eslint . --fix",
1515
"type-check": "tsc --noEmit",
1616
"generate:sw": "GITHUB_SHA=$GITHUB_SHA node scripts/generate-sw.js",
17-
"build:wasm": "cd worker/rust_ai_core && wasm-pack build --release --target web --out-dir ../../public/wasm --features wasm",
17+
"build:wasm": "cd worker && wasm-pack build --release --target web --out-dir ../public/wasm --features wasm",
1818
"build:wasm-assets": "npm run build:wasm && mkdir -p public/ml/data/genetic_params && cp resources/ai/evolved.json public/ml/data/genetic_params/ && mkdir -p public/ml/data/weights && cp public/ml/data/weights/ml_ai_weights_best.json public/ml/data/weights/ml_ai_weights_simple.json",
19-
"build:rust-ai": "cd worker/rust_ai_core && cargo build --release",
19+
"build:rust-ai": "cd worker && cargo build --release",
2020
"nuke": "rm -rf .next .open-next .wrangler node_modules package-lock.json && npm install && npm run dev",
21-
"check": "npm run lint && npm run type-check && (cd worker/rust_ai_core && NUM_GAMES=4 cargo test test_ai_matrix -- --nocapture) && npm run test:coverage && npm run test:e2e",
22-
"check:slow": "npm run lint && npm run type-check && (cd worker/rust_ai_core && RUN_SLOW_TESTS=1 cargo test --features slow_tests -- --nocapture) && npm run test:coverage && npm run test:e2e",
21+
"check": "npm run lint && npm run type-check && (cd worker && NUM_GAMES=4 cargo test test_ai_matrix -- --nocapture) && npm run test:coverage && npm run test:e2e",
22+
"check:slow": "npm run lint && npm run type-check && (cd worker && RUN_SLOW_TESTS=1 cargo test --features slow_tests -- --nocapture) && npm run test:coverage && npm run test:e2e",
2323
"test": "vitest run",
2424
"test:watch": "vitest",
2525
"test:coverage": "vitest run --coverage",
26-
"test:rust": "cd worker/rust_ai_core && cargo test -- --nocapture",
27-
"test:rust:slow": "cd worker/rust_ai_core && RUN_SLOW_TESTS=1 cargo test --features slow_tests -- --nocapture",
26+
"test:rust": "cd worker && cargo test -- --nocapture",
27+
"test:rust:slow": "cd worker && RUN_SLOW_TESTS=1 cargo test --features slow_tests -- --nocapture",
2828
"test:ai-comparison": "./scripts/test-ai-comparison.sh",
2929
"test:ai-comparison:default": "NUM_GAMES=50 ./scripts/test-ai-comparison.sh",
3030
"test:ai-comparison:fast": "NUM_GAMES=10 ./scripts/test-ai-comparison.sh",
@@ -39,7 +39,7 @@
3939
"migrate:generate": "drizzle-kit generate",
4040
"migrate:d1": "wrangler d1 migrations apply connect-four-db --remote",
4141
"migrate:local": "drizzle-kit push --config=drizzle.config.local.ts",
42-
"test:ai-matrix:md": "cd worker/rust_ai_core && cargo test test_ai_matrix -- --nocapture | node ../../scripts/format-ai-matrix-md.cjs",
42+
"test:ai-matrix:md": "cd worker && cargo test test_ai_matrix -- --nocapture | node ../scripts/format-ai-matrix-md.cjs",
4343
"deploy": "./scripts/deploy.sh",
4444
"deploy:quick": "npm run build:cf && wrangler deploy",
4545
"db:migrate": "wrangler d1 migrations apply connect-four-db --remote",

scripts/generate-types.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
set -e
33

44
echo "🦀 Generating Types from Rust..."
5-
cd worker/rust_ai_core
5+
cd worker
66
# Run the test that exports the bindings
77
cargo test --test bindings_test --features wasm
88

99
echo "📦 Bundling bindings to frontend..."
10-
DEST_FILE="../../src/lib/bindings.ts"
10+
DEST_FILE="../src/lib/bindings.ts"
1111
BINDINGS_DIR="bindings"
1212

1313
# Remove the old directory if it exists (since we are switching to a single file)
14-
rm -rf ../../src/lib/bindings
14+
rm -rf ../src/lib/bindings
1515

1616
echo "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually." > "$DEST_FILE"
1717

scripts/test-ai-comparison.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ echo "🤖 Running AI Comparison Tests..."
99

1010
# Build the Rust core
1111
echo "🔨 Building Rust AI core..."
12-
cd worker/rust_ai_core
12+
cd worker
1313
cargo build
14-
cd ../..
14+
cd ..
1515

1616
# Run the AI matrix test
1717
echo "🧪 Running AI Matrix Test..."
18-
cd worker/rust_ai_core
18+
cd worker
1919
cargo test test_ai_matrix -- --ignored --nocapture
20-
cd ../..
20+
cd ..
2121

2222
echo "✅ AI Comparison Tests Complete!"

src/lib/utils/getAIVersion.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ export async function getClassicAIVersion(): Promise<string> {
88
const { createHash } = await import('crypto');
99

1010
// Get the Rust crate version
11-
const cargoTomlPath = 'worker/rust_ai_core/Cargo.toml';
11+
const cargoTomlPath = 'worker/Cargo.toml';
1212
const cargoContent = readFileSync(cargoTomlPath, 'utf8');
1313
const versionMatch = cargoContent.match(/version = "([^"]+)"/);
1414
const crateVersion = versionMatch ? versionMatch[1] : '0.1.0';
1515

1616
// Get a hash of the AI-specific source files to detect AI changes
1717
const aiSourceFiles = [
18-
'worker/rust_ai_core/src/lib.rs',
19-
'worker/rust_ai_core/src/features.rs',
20-
'worker/rust_ai_core/src/ml_ai.rs',
21-
'worker/rust_ai_core/src/neural_network.rs',
18+
'worker/src/lib.rs',
19+
'worker/src/features.rs',
20+
'worker/src/ml_ai.rs',
21+
'worker/src/neural_network.rs',
2222
];
2323

2424
const hash = createHash('sha256');

worker/Cargo.toml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,55 @@
1-
[workspace]
2-
resolver = "2"
3-
members = [
4-
"rust_ai_core"
1+
[package]
2+
name = "connect-four-ai-core"
3+
version = "1.0.0"
4+
edition = "2021"
5+
authors = ["Robert Gilks"]
6+
description = "Connect Four AI core logic"
7+
license = "MIT"
8+
repository = "https://github.com/robertgilks/connect-four"
9+
10+
[package.metadata.wasm-pack.profile.release]
11+
wasm-opt = false
12+
13+
[lib]
14+
crate-type = ["cdylib", "rlib"]
15+
16+
[[bin]]
17+
name = "connect-four-ai-worker"
18+
path = "src/main.rs"
19+
20+
[features]
21+
default = []
22+
wasm = [
23+
"wasm-bindgen",
24+
"console_error_panic_hook",
25+
"getrandom/js",
26+
"dep:js-sys",
27+
"dep:web-sys",
28+
"dep:serde-wasm-bindgen",
529
]
30+
training = []
31+
slow_tests = []
632

7-
[workspace.dependencies]
33+
[dependencies]
834
serde = { version = "1.0", features = ["derive"] }
9-
wasm-bindgen = "0.2.100"
35+
serde_json = { version = "1.0", features = ["preserve_order"] }
36+
rand = { version = "0.8.5", features = ["getrandom"] }
37+
uuid = { version = "1.0", features = ["v4", "serde", "js"] }
38+
getrandom = { version = "0.2", features = ["js"] }
39+
wasm-bindgen = { version = "0.2.100", optional = true }
40+
serde-wasm-bindgen = { version = "0.6.5", optional = true }
41+
console_error_panic_hook = { version = "0.1.7", optional = true }
42+
js-sys = { version = "0.3", optional = true }
43+
web-sys = { version = "0.3", optional = true, features = ["console"] }
44+
lazy_static = "1.4"
45+
ndarray = "0.15"
46+
chrono = { version = "0.4", features = ["serde"] }
47+
rayon = "1.8"
48+
tempfile = "3.8"
49+
ts-rs = "7.0.0"
50+
51+
[dev-dependencies]
52+
criterion = "0.6.0"
1053

1154
[profile.release]
1255
opt-level = 3

worker/rust_ai_core/Cargo.toml

Lines changed: 0 additions & 53 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)