stemedb/applications/aphoria/examples/scale_adaptive_demo.rs
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

89 lines
3.2 KiB
Rust

//! Demonstrates scale-adaptive promotion thresholds.
//!
//! Run with: `cargo run --example scale_adaptive_demo`
use aphoria::corpus::thresholds::{ScaleAdaptiveThresholds, ScaleTier};
fn main() {
println!("=== Scale-Adaptive Promotion Thresholds Demo ===\n");
let thresholds = ScaleAdaptiveThresholds::default();
// Scenario 1: Micro Team (3 projects)
println!("📊 Scenario 1: Micro Team (3 projects)");
println!("Pattern appears in 2 out of 3 projects (67% adoption)\n");
let tier = ScaleTier::from_total_projects(3);
println!(" Scale Tier: {:?}", tier);
let decision = thresholds.evaluate(2, 3, false, None);
println!(" Decision: {:?}", decision);
println!(" ✅ Pattern VISIBLE to team (RequireReview)\n");
// Scenario 2: Small Team with RFC match
println!("📊 Scenario 2: Small Team (10 projects)");
println!("Pattern appears in 9 projects with RFC match (90% adoption)\n");
let tier = ScaleTier::from_total_projects(10);
println!(" Scale Tier: {:?}", tier);
let decision = thresholds.evaluate(9, 10, true, Some("rfc://5246"));
println!(" Decision: {:?}", decision);
println!(" ✅ Auto-promoted to Regulatory tier\n");
// Scenario 3: Enterprise (1000 projects)
println!("📊 Scenario 3: Enterprise (1000 projects)");
println!("Pattern appears in 950 projects with RFC match (95% adoption)\n");
let tier = ScaleTier::from_total_projects(1000);
println!(" Scale Tier: {:?}", tier);
let decision = thresholds.evaluate(950, 1000, true, Some("rfc://9110"));
println!(" Decision: {:?}", decision);
println!(" ✅ Auto-promoted to Regulatory tier (backward compatible)\n");
// Scenario 4: Noise prevention
println!("📊 Scenario 4: Noise Prevention (3 projects)");
println!("Pattern appears in only 1 project (33% adoption)\n");
let tier = ScaleTier::from_total_projects(3);
println!(" Scale Tier: {:?}", tier);
let decision = thresholds.evaluate(1, 3, false, None);
println!(" Decision: {:?}", decision);
println!(" ✅ Skipped (floor prevents single-project noise)\n");
// Show threshold matrix
println!("=== Threshold Matrix ===\n");
println!("| Tier | Projects | Emerging Floor | Regulatory Floor |");
println!("|------------|----------|----------------|------------------|");
for (name, total) in [
("Micro", 3),
("Small", 10),
("Medium", 50),
("Large", 200),
("Enterprise", 1000),
] {
let tier = ScaleTier::from_total_projects(total);
let tier_thresholds = thresholds.for_tier(tier);
let emerging_min = tier_thresholds.emerging.effective_min_projects(total);
let regulatory_min = if let Some(reg) = &tier_thresholds.regulatory {
format!("{}", reg.effective_min_projects(total))
} else {
"N/A".to_string()
};
println!(
"| {:10} | {:8} | {:14} | {:16} |",
name, total, emerging_min, regulatory_min
);
}
println!("\n✅ Small teams see value immediately!");
println!("✅ Quality maintained via floors and adoption rates!");
println!("✅ Enterprise behavior unchanged!");
}