.cursor/skills/ble-implementation-patterns/SKILL.md
--- name: ble-implementation-patterns description: Guides BLE implementation: device discovery, background scanning, power optimization, platform-specific implementations (Android/iOS). Use when implementing Bluetooth Low Energy features or device discovery. --- # BLE Implementation Patterns ## Core Purpose Bluetooth Low Energy (BLE) enables device discovery and personality data advertising in AI2AI system. ## Platform Support - **Android:** BLE APIs with foreground service for background -
npx skillsauth add avra-cadavra/avrai .cursor/skills/ble-implementation-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Bluetooth Low Energy (BLE) enables device discovery and personality data advertising in AI2AI system.
/// BLE Device Discovery Service
///
/// Discovers nearby SPOTS-enabled devices using BLE
class BLEDeviceDiscoveryService {
final BLEScanner _scanner;
/// Start BLE scanning
Future<void> startDiscovery({
Duration scanInterval = const Duration(seconds: 5),
Duration scanWindow = const Duration(seconds: 4),
}) async {
// Start continuous scanning
await _scanner.startScan(
serviceUuid: spotsServiceUuid, // Filter by service UUID
scanInterval: scanInterval,
scanWindow: scanWindow,
);
}
/// Stop BLE scanning
Future<void> stopDiscovery() async {
await _scanner.stopScan();
}
}
Use hardware-level filtering for power efficiency:
/// SPOTS Service UUID for hardware-level filtering
static const String spotsServiceUuid = '0000ff00-0000-1000-8000-00805f9b34fb';
/// Start scanning with service UUID filter
await ble.scan(
withServices: [Guid(spotsServiceUuid)],
scanMode: ScanMode.lowPower,
);
Use foreground service for background BLE:
/// BLE Foreground Service (Android)
///
/// Enables continuous BLE scanning in background
class BLEForegroundService extends Service {
@override
void onCreate() {
super.onCreate();
startForeground(
NOTIFICATION_ID,
createNotification(),
);
startBLEScanning();
}
void startBLEScanning() {
// Start BLE scanning
// Runs continuously in background
}
}
Configure background modes for iOS:
<!-- Info.plist -->
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
Scan for short periods, sleep in between:
/// Adaptive BLE Scanning
///
/// Adjusts scan frequency based on battery level and usage patterns
class AdaptiveBLEScanner {
Future<void> startAdaptiveScanning() async {
final batteryLevel = await getBatteryLevel();
if (batteryLevel > 50) {
// High battery: Scan more frequently
await scan(interval: Duration(seconds: 3));
} else if (batteryLevel > 20) {
// Medium battery: Normal scanning
await scan(interval: Duration(seconds: 5));
} else {
// Low battery: Reduced scanning
await scan(interval: Duration(seconds: 10));
}
}
}
/// Scan for 1 second, sleep for 4 seconds (intermittent)
await scanner.startScan(
scanInterval: Duration(seconds: 5),
scanWindow: Duration(seconds: 1), // Scan for 1 second
);
Advertise anonymized personality data:
/// Personality Advertising Service
///
/// Advertises anonymized personality data via BLE
class PersonalityAdvertisingService {
final BLEAdvertiser _advertiser;
/// Start advertising personality data
Future<void> startAdvertising() async {
final personalityData = extractAnonymizedPersonality();
await _advertiser.startAdvertising(
serviceUuid: spotsServiceUuid,
manufacturerData: personalityData.toBytes(),
);
}
}
// lib/core/network/device_discovery_android.dart
class BLEDeviceDiscoveryAndroid implements BLEDeviceDiscovery {
// Android-specific BLE implementation
// Uses Android BLE APIs
// Supports foreground service for background
}
// lib/core/network/device_discovery_ios.dart
class BLEDeviceDiscoveryIOS implements BLEDeviceDiscovery {
// iOS-specific BLE implementation
// Uses Core Bluetooth framework
// Supports background modes
}
docs/ai2ai/06_network_connectivity/BLE_IMPLEMENTATION.mddocs/ai2ai/06_network_connectivity/BLE_BACKGROUND.mdlib/core/network/device_discovery_android.dartlib/core/network/device_discovery_ios.dartdevelopment
--- name: world-model-development description: Guides world model development patterns: state/action encoders, ONNX inference, feature extraction pipeline, latency budgets. Use when implementing world model components, state encoders, action encoders, feature extractors, or ONNX models. Core skill for Phases 3-6. --- # World Model Development Patterns ## Core Principle All world model components follow LeCun's autonomous machine intelligence framework. State observations flow through a percep
tools
Implements base workflow controller patterns for multi-step processes. Use when creating complex workflows that require orchestration of multiple steps with error handling and rollback.
testing
--- name: widget-test-patterns description: Guides widget test patterns: BLoC testing, user interactions, state changes, material app setup. Use when writing widget tests, testing UI components, or validating widget behavior. --- # Widget Test Patterns ## Core Pattern Widget tests verify UI behavior: user interactions, state changes, and visual display. ## Basic Widget Test Setup ```dart testWidgets('widget displays correctly', (WidgetTester tester) async { // Arrange: Create widget awa
testing
--- name: test-template-generation description: Generates test templates: unit, widget, integration, service tests following project patterns. Use when creating new tests or ensuring tests follow project standards. --- # Test Template Generation ## Available Templates Test templates are located in `test/templates/`: - `unit_test_template.dart` - `widget_test_template.dart` - `integration_test_template.dart` - `service_test_template.dart` ## Unit Test Template ```dart /// SPOTS Component Uni