This document provides detailed workflows and troubleshooting for AI coding agents working in this repository.
Quick Start: For essential architecture patterns and conventions, see
.github/copilot-instructions.mdfirst.
This guide focuses on comprehensive build workflows, testing procedures, and detailed troubleshooting steps.
kord/(akaklib): Core music theory/audio/ML library and CLI. Pest grammar atkord/chord.pest; parser atkord/src/core/parser.rs.kord-web/: Leptos 0.8 SSR app with client hydration (Axum SSR). Also builds to WASI/WASM for edge-like SSR.- Loader/target features are forwarded explicitly: default
kord_loader_note_binnedenablesml_loader_note_binned_convolution+ml_target_fullonklib. Disable defaults and opt intokord_loader_frequencywhen you need the folded-bass path (ml_loader_frequency+ml_target_folded_bass).
- Loader/target features are forwarded explicitly: default
Key feature flags (core crate):
- Defaults:
default = ["cli", "analyze", "audio"] cli: CLI binary featuresanalyze = ["analyze_mic", "analyze_file"]ml = ["ml_train", "ml_infer"], optionalml_gpuwasm/wasiaudio
Data/model artifacts used by analysis/ML are in kord/model/, kord/noise/, and kord/samples/.
Core (library + CLI):
cargo build -p kord
cargo make test # in remote agents, sometimes `cargo-make` is required.Web (SSR + hydrate):
cd kord-web
cargo check --features ssr,hydrate
cargo leptos watchWASM (npm package):
wasm-pack build --features ml_infer --features wasm- Prereqs (Linux): install ALSA headers for audio support
sudo apt-get update && sudo apt-get install -y libasound2-dev- Build core and CLI:
cargo build -p kord- Run tests:
cargo make test- Types/traits:
Note,Chord,Modifier; builder viaChordable. - Parsing:
Parsablewith Pest grammar inkord/chord.pestand logic inkord/src/core/parser.rs. - Errors:
anyhow::Result<T>aliased asRes<T>; use for fallible functions. - Statics: prefer
LazyLockfor computed tables (seecore/modifier.rs). - Audio analysis: normalized FFT space (8192 bins to C9).
- ML: config via
TrainConfig; constants inkord/src/ml/base/mod.rs(e.g.,FREQUENCY_SPACE_SIZE).
From kord-web/:
- Developer server with SSR + client hydrate:
cargo leptos watch- Type-check with SSR + Hydrate features (useful for CI/agents):
cd kord-web
cargo check --features ssr,hydrate- Release build (SSR binary + client assets):
cargo leptos build --release- SSR/hydrate: the lib builds with
hydrate; the bin builds withssr. Keep parity across both features. - App shell: wrap with
thaw::ssr::SSRMountStyleProviderandthaw::ConfigProvider(custom theme) inkord-web/src/app/mod.rs. - Callbacks: Thaw expects
on_click: Option<BoxOneCallback<MouseEvent>>. Usethaw_utilshelpers and shared wrappers. - Inputs: bind
thaw::InputwithRwSignal<String>. - Layout/typography: use
Space/Flex;TextwithTextTagfor headings. - Forms: prefer
Field label="…"wrappingInputinstead of raw labels. - Timing: use
leptos-useutilities (e.g.,use_timestamp) over manual intervals. - Shared UI: reuse components in
kord-web/src/app/shared.rsfor consistent Thaw integration.
- Build SSR library targeting
wasm32-wasip2:
export LEPTOS_OUTPUT_NAME=kord-web
cargo build --lib --release --target wasm32-wasip2 --no-default-features --features ssr -p kord-web- Run with Wasmtime (example):
wasmtime serve ./target/wasm32-wasip2/release/kord_web.wasm -S cli- Build the WASM package exposing the core API for JS:
wasm-pack build --features ml_infer --features wasm- Publish flow (summary): rename package to
kordweb, thenwasm-pack publish.
- Build and publish the CLI as a WebAssembly component to GitHub Container Registry:
cargo make build-oci
cargo make publish-oci- Users can run with any WASI-compatible runtime:
wasmtime run ghcr.io/twitchax/kord:latest describe Am7- Chord grammar lives in
kord/chord.pest. - Parsing implementation is in
kord/src/core/parser.rs. - When extending grammar:
- Update both the
.pestrules and corresponding parser code. - Add targeted tests under
kord/src/**or workspace tests underkord/tests/**. - Keep backward compatibility for existing chord strings when possible.
- Update both the
- Keep changes minimal and focused; avoid unrelated refactors.
- Respect feature gating patterns (
#[cfg(feature = "…")]) and keep SSR/hydrate parity for the web app. - Prefer fixing root causes over surface workarounds; don’t change public APIs unless required.
- Follow existing style; don’t add license headers; avoid one-letter variable names.
- Web UI (Leptos + Thaw):
- Use
thaw_utilscallback helpers (BoxOneCallback/ArcOneCallback) per existing components. - Bind
thaw::Inputvalues viaRwSignal<String>(Model). - Use shared wrappers from
kord-web/src/app/shared.rsfor consistent UI.
- Use
- When editing code, validate with targeted checks:
- Core:
cargo make test - Web:
cd kord-web && cargo check --features ssr,hydrate - Full workspace checks are good before PRs:
cargo make test+cargo check.
- Core:
- Prefer pointer events for cross-input support; ensure release/cancel stops any audio.
- Gate browser-only code with
#[cfg(feature = "hydrate")]and provide server fallbacks. - Keep DOM-dependent code out of SSR paths; use feature flags or runtime checks.
- Describe a chord (CLI):
kord describe Cmaj7- Guess from audio (deterministic vs ML):
kord analyze mic
kord ml infer mic- Run library tests for the core crate as usual.
- For the web crate, prefer type-checking both SSR and hydrate features:
cd kord-web
cargo check --features ssr,hydrate- Integration tests are run as part of the main test suite:
cargo make test- If audio-related crates fail to build on Linux, ensure
libasound2-devis installed. - For proc-macro ABI cache issues during development, a clean rebuild can help:
cargo clean -p kord-web && cargo check -p kord-web --features ssr,hydrate- If
cargo leptosis missing, install it (prefer binstall for speed):
cargo binstall cargo-leptos
# or: cargo install cargo-leptos- WASM/WASI tooling often needed for advanced flows:
cargo binstall wkg # for OCI publishing
cargo binstall wasm-pack # for npm/wasm builds
brew install wasmtime || sudo apt-get install wasmtime- For faster tool installation, use cargo-binstall:
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bashThis guide consolidates details from the top-level README and DEVELOPMENT notes to make automated and human contributions faster and safer. If something seems off or you need more detail, check README.md and DEVELOPMENT.md for the authoritative context.