stemedb/.claude/guides/local/setup.md
jml bb0c33f8d3 fix(api): enable querying of CLI-created community corpus items
## Problem
CLI-created community corpus items (tier 3) were stored correctly but
invisible via API queries. Two issues blocked discoverability:

1. **Prefix mismatch**: API hardcoded 'community://pattern/' for
   aggregated patterns, but CLI creates 'community://rust/http/...' URIs
2. **Query parameter parsing**: Axum's default parser doesn't support
   bracket notation (?sources[]=value) used by the dashboard

Result: 0/22 CLI-created items were queryable.

## Solution

### Fix 1: Broaden Community Prefix
- Changed: 'community://pattern/' → 'community://' in corpus handler
- Impact: Now matches both aggregated patterns AND CLI-created items
- Backward compatible: Broader prefix includes narrower results

### Fix 2: Add QsQuery Extractor
- Added: serde_qs dependency + custom QsQuery extractor
- Supports: Bracket notation for array parameters (?sources[]=a&sources[]=b)
- Compatible: Works with JavaScript URLSearchParams standard
- Tested: 3 new unit tests for extractor behavior

## Verification
-  All 22 CLI-created community items now queryable (was 0)
-  Source filtering works: community (22), RFC (2), vendor (5)
-  Multi-source queries work: ?sources[]=community&sources[]=rfc → 24
-  All 89 API tests pass + 3 new extractor tests
-  Clippy clean (0 warnings)
-  No regressions in existing functionality

## Files Changed
- crates/stemedb-api/Cargo.toml: Add serde_qs dependency
- crates/stemedb-api/src/extractors.rs: New QsQuery extractor (117 lines)
- crates/stemedb-api/src/handlers/aphoria/corpus.rs: Use QsQuery, broaden prefix
- crates/stemedb-api/src/lib.rs: Export extractors module

Also includes: Scale-adaptive thresholds, wiki corpus extraction,
documentation updates, and dashboard UI improvements from prior work.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-09 15:54:35 +00:00

112 lines
2.4 KiB
Markdown

# Local Development Setup
**When to use:** Setting up StemeDB for local development.
## Prerequisites
- Rust 1.75+ (2024 edition)
- `cargo` and `rustup`
## Quick Start
```bash
# Clone and enter
cd stemedb
# Build everything
cargo build --workspace
# Run tests
cargo test --workspace
# Run lints (must pass)
cargo clippy --workspace -- -D warnings
cargo fmt --check
```
## IDE Setup
### VS Code
Install extensions:
- rust-analyzer
- Even Better TOML
- Error Lens (optional, shows inline errors)
Settings (`.vscode/settings.json`):
```json
{
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.allTargets": true
}
```
### JetBrains (RustRover/CLion)
- Enable Clippy as default checker
- Set rustfmt on save
## Project Structure
```
stemedb/
CLAUDE.md # AI router (start here)
CODING_GUIDELINES.md # Rust standards
Cargo.toml # Workspace root
crates/
stemedb-core/ # Core types and storage
.claude/
agents/ # Specialized AI agents
commands/ # Slash commands
skills/ # Reusable procedures
guides/ # You are here
```
## Git Hooks
The repository includes automatic git hooks to rebuild binaries when source code changes:
- **post-merge**: Runs after `git pull` or `git merge`
- **post-checkout**: Runs after `git checkout` (branch switches only)
These hooks detect changes to:
- Aphoria CLI and core logic
- StemeDB API server
- StemeDB simulator
- Core libraries (affects all binaries)
When changes are detected, the hooks automatically run `cargo build --release --workspace` to rebuild all binaries. This prevents "command not found" errors from stale binaries.
The hooks are installed in `.git/hooks/` and are already executable. If you need to disable them temporarily, you can use `--no-verify` with git commands or rename the hook files.
## Troubleshooting
### Build fails with missing dependencies
```bash
rustup update
cargo clean
cargo build
```
### Clippy warnings
Run with `--fix` for auto-corrections:
```bash
cargo clippy --workspace --fix --allow-dirty
```
### "Command not found" after git pull
If you see this error despite the git hooks, manually rebuild:
```bash
cargo build --release --workspace
```
The binaries are in `target/release/` and should be in your PATH or called via `cargo run --release -p <package>`.
## Related
- [Testing Guide](./testing.md)
- [Rust Guidelines](../backend/rust-guidelines.md)