chore(skills): add Nightwatch and MCP agent skills
Add Nightwatch configuration guidance and MCP development skill docs across agent integrations, and refresh existing Laravel skill references.
This commit is contained in:
parent
018d267b3f
commit
8aea029782
134 changed files with 2123 additions and 215 deletions
404
.agents/skills/configure-nightwatch/SKILL.md
Normal file
404
.agents/skills/configure-nightwatch/SKILL.md
Normal file
|
|
@ -0,0 +1,404 @@
|
||||||
|
---
|
||||||
|
name: configure-nightwatch
|
||||||
|
description: Configures Laravel Nightwatch data collection, sampling rates, filtering rules, and redaction policies. Use when setting up Nightwatch, managing data volume, protecting sensitive data (PII), or optimizing event collection for production workloads.
|
||||||
|
license: MIT
|
||||||
|
metadata:
|
||||||
|
author: laravel
|
||||||
|
---
|
||||||
|
|
||||||
|
# Nightwatch Configuration Guide
|
||||||
|
|
||||||
|
This skill helps configure Laravel Nightwatch data collection to balance observability, performance, and privacy. Covers sampling strategies, filtering rules, and redaction methods across all event types.
|
||||||
|
|
||||||
|
## Documentation Reference
|
||||||
|
|
||||||
|
The [Nightwatch Documentation](https://nightwatch.laravel.com/docs) is the definitive and up-to-date source of information for all Nightwatch configuration options. This skill provides practical guidance and common patterns, but always consult the official documentation as the primary source of truth for specific details, environment variables, and API behavior. The documentation includes comprehensive coverage of:
|
||||||
|
|
||||||
|
- [Filtering and Configuration](https://nightwatch.laravel.com/docs/filtering) - Core concepts for sampling, filtering, and redaction
|
||||||
|
- Individual event type pages with specific configuration options:
|
||||||
|
- [Requests](https://nightwatch.laravel.com/docs/requests) - Request sampling, header handling, payload capture
|
||||||
|
- [Commands](https://nightwatch.laravel.com/docs/commands) - Command sampling and redaction
|
||||||
|
- [Queries](https://nightwatch.laravel.com/docs/queries) - Query filtering and redaction
|
||||||
|
- [Cache](https://nightwatch.laravel.com/docs/cache) - Cache event filtering by key or pattern
|
||||||
|
- [Jobs](https://nightwatch.laravel.com/docs/jobs) - Job filtering and sampling decoupling
|
||||||
|
- [Mail](https://nightwatch.laravel.com/docs/mail) - Mail event filtering
|
||||||
|
- [Notifications](https://nightwatch.laravel.com/docs/notifications) - Notification filtering by channel
|
||||||
|
- [Exceptions](https://nightwatch.laravel.com/docs/exceptions) - Exception sampling and throttling
|
||||||
|
- [Outgoing Requests](https://nightwatch.laravel.com/docs/outgoing-requests) - HTTP request filtering
|
||||||
|
- [reference.md](reference.md) - Quick lookup table by event type, production presets, and verification checklist
|
||||||
|
|
||||||
|
## Data Collection Flow
|
||||||
|
|
||||||
|
Nightwatch processes events through three stages:
|
||||||
|
|
||||||
|
1. **Sampling** - Controls which entry points are captured (requests, commands, scheduled tasks)
|
||||||
|
2. **Filtering** - Excludes specific events after sampling (queries, cache, mail, etc.)
|
||||||
|
3. **Redaction** - Modifies captured data to remove/obfuscate sensitive information
|
||||||
|
|
||||||
|
```
|
||||||
|
Request/Command/Scheduled Task
|
||||||
|
|
|
||||||
|
v
|
||||||
|
[Sampling?] ----NO----> Drop entire trace
|
||||||
|
| YES
|
||||||
|
v
|
||||||
|
Events generated
|
||||||
|
|
|
||||||
|
v
|
||||||
|
[Filtering?] ----YES---> Drop specific event
|
||||||
|
| NO
|
||||||
|
v
|
||||||
|
[Redaction] ----------> Store modified data
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sampling Configuration
|
||||||
|
|
||||||
|
Sampling determines which entry points (requests, commands, scheduled tasks) trigger full trace collection. When an entry point is sampled, all related events are captured.
|
||||||
|
|
||||||
|
### Global Sample Rates
|
||||||
|
|
||||||
|
Configure via environment variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Default: 100% sampling (all requests/commands captured)
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1 # Recommended: 10% of requests
|
||||||
|
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0 # Capture all commands
|
||||||
|
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0 # Always capture exceptions
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**Recommendation**: Start with `0.1` (10%) for requests in production, adjust based on volume and needs.
|
||||||
|
|
||||||
|
### Route-Based Sampling
|
||||||
|
|
||||||
|
Apply different rates to specific routes using the `Sample` middleware:
|
||||||
|
|
||||||
|
```php routes/web.php
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Laravel\Nightwatch\Http\Middleware\Sample;
|
||||||
|
|
||||||
|
// Sample admin routes at 100%
|
||||||
|
Route::middleware(Sample::rate(1.0))->prefix('admin')->group(function () {
|
||||||
|
// All admin routes sampled fully
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sample API routes at 5%
|
||||||
|
Route::middleware(Sample::rate(0.05))->prefix('api')->group(function () {
|
||||||
|
// API routes sampled sparingly
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always sample critical endpoints
|
||||||
|
Route::post('/checkout', [CheckoutController::class, 'process'])
|
||||||
|
->middleware(Sample::always());
|
||||||
|
|
||||||
|
// Never sample health checks
|
||||||
|
Route::get('/health', [HealthController::class, 'check'])
|
||||||
|
->middleware(Sample::never());
|
||||||
|
```
|
||||||
|
|
||||||
|
### Unmatched Route Sampling
|
||||||
|
|
||||||
|
Handle 404/bot traffic with reduced sampling:
|
||||||
|
|
||||||
|
```php routes/web.php
|
||||||
|
Route::fallback(fn () => abort(404))
|
||||||
|
->middleware(Sample::rate(0.01)); // 1% sampling for unmatched routes
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dynamic Sampling
|
||||||
|
|
||||||
|
Sample based on runtime conditions (user role, request attributes):
|
||||||
|
|
||||||
|
```php app/Http/Middleware/SampleAdminRequests.php
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
|
||||||
|
class SampleAdminRequests
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
if ($request->user()?->isAdmin()) {
|
||||||
|
Nightwatch::sample(); // Always sample admin requests
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command Sampling
|
||||||
|
|
||||||
|
Exclude specific commands from sampling:
|
||||||
|
|
||||||
|
```php AppServiceProvider.php
|
||||||
|
use Illuminate\Console\Events\CommandStarting;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Event::listen(function (CommandStarting $event) {
|
||||||
|
if (in_array($event->command, ['schedule:finish', 'horizon:snapshot'])) {
|
||||||
|
Nightwatch::dontSample();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vendor Commands
|
||||||
|
|
||||||
|
Nightwatch automatically ignores framework/internal commands. Opt-in to capture them:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::captureDefaultVendorCommands();
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Filtering Configuration
|
||||||
|
|
||||||
|
Filtering excludes specific events from collection after sampling. Use filtering to reduce noise and quota usage.
|
||||||
|
|
||||||
|
### Database Queries
|
||||||
|
|
||||||
|
**Filter all queries** (disable query collection):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_QUERIES=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter specific queries** by SQL pattern:
|
||||||
|
|
||||||
|
```php AppServiceProvider.php
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
use Laravel\Nightwatch\Records\Query;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
// Filter job table queries (PostgreSQL)
|
||||||
|
Nightwatch::rejectQueries(function (Query $query) {
|
||||||
|
return str_contains($query->sql, 'into "jobs"');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter cache table queries (MySQL)
|
||||||
|
Nightwatch::rejectQueries(function (Query $query) {
|
||||||
|
return str_contains($query->sql, 'from `cache`')
|
||||||
|
|| str_contains($query->sql, 'into `cache`');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cache Events
|
||||||
|
|
||||||
|
**Filter all cache events**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_CACHE_EVENTS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by cache key patterns**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::rejectCacheKeys([
|
||||||
|
'my-app:users', // Exact match
|
||||||
|
'/^my-app:posts:/', // Regex: starts with my-app:posts:
|
||||||
|
'/^[a-zA-Z0-9]{40}$/', // Regex: session IDs
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter with callback**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\CacheEvent;
|
||||||
|
|
||||||
|
Nightwatch::rejectCacheEvents(function (CacheEvent $cacheEvent) {
|
||||||
|
return str_starts_with($cacheEvent->key, 'temp:');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mail Events
|
||||||
|
|
||||||
|
**Filter all mail**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_MAIL=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter specific mail**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Mail;
|
||||||
|
|
||||||
|
Nightwatch::rejectMail(function (Mail $mail) {
|
||||||
|
return str_contains($mail->subject, 'Newsletter');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Notification Events
|
||||||
|
|
||||||
|
**Filter all notifications**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_NOTIFICATIONS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by channel**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Notification;
|
||||||
|
|
||||||
|
Nightwatch::rejectNotifications(function (Notification $notification) {
|
||||||
|
return $notification->channel === 'database';
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Outgoing HTTP Requests
|
||||||
|
|
||||||
|
**Filter all outgoing requests**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_OUTGOING_REQUESTS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by URL**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\OutgoingRequest;
|
||||||
|
|
||||||
|
Nightwatch::rejectOutgoingRequests(function (OutgoingRequest $request) {
|
||||||
|
return str_contains($request->url, 'analytics.example.com');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Queued Jobs
|
||||||
|
|
||||||
|
**Filter specific jobs**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\QueuedJob;
|
||||||
|
|
||||||
|
Nightwatch::rejectQueuedJobs(function (QueuedJob $job) {
|
||||||
|
return $job->name === 'App\Jobs\LowPriorityJob';
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Decoupling Job Sampling
|
||||||
|
|
||||||
|
Sample jobs independently from parent contexts:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Illuminate\Support\Facades\Queue;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Queue::before(fn () => Nightwatch::sample(rate: 0.5));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Redaction Configuration
|
||||||
|
|
||||||
|
Redaction modifies captured data to remove or obfuscate sensitive information. Unlike filtering, redaction keeps the event but sanitizes its content.
|
||||||
|
|
||||||
|
### Request Redaction
|
||||||
|
|
||||||
|
**Redact sensitive headers** (automatically redacts: Authorization, Cookie, X-XSRF-TOKEN):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Customize redacted headers
|
||||||
|
|
||||||
|
NIGHTWATCH_REDACT_HEADERS=Authorization,Cookie,Proxy-Authorization,X-API-Key
|
||||||
|
```
|
||||||
|
|
||||||
|
**Redact request payloads** (disabled by default):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Enable payload capture
|
||||||
|
|
||||||
|
NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD=true
|
||||||
|
|
||||||
|
# Customize redacted fields
|
||||||
|
|
||||||
|
NIGHTWATCH_REDACT_PAYLOAD_FIELDS=password,password_confirmation,ssn,credit_card
|
||||||
|
```
|
||||||
|
|
||||||
|
**Programmatic redaction**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
use Laravel\Nightwatch\Records\Request;
|
||||||
|
|
||||||
|
Nightwatch::redactRequests(function (Request $request) {
|
||||||
|
$request->url = str_replace('secret', '***', $request->url);
|
||||||
|
$request->ip = preg_replace('/\d+$/', '***', $request->ip);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Query Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Query;
|
||||||
|
|
||||||
|
Nightwatch::redactQueries(function (Query $query) {
|
||||||
|
$query->sql = str_replace('secret_token', '***', $query->sql);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cache Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\CacheEvent;
|
||||||
|
|
||||||
|
Nightwatch::redactCacheEvents(function (CacheEvent $cacheEvent) {
|
||||||
|
$cacheEvent->key = str_replace('user:', 'user:***:', $cacheEvent->key);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Command;
|
||||||
|
|
||||||
|
Nightwatch::redactCommands(function (Command $command) {
|
||||||
|
$command->command = preg_replace('/--password=\S+/', '--password=***', $command->command);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exception Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Exception;
|
||||||
|
|
||||||
|
Nightwatch::redactExceptions(function (Exception $exception) {
|
||||||
|
$exception->message = str_replace('secret', '***', $exception->message);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mail Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Mail;
|
||||||
|
|
||||||
|
Nightwatch::redactMail(function (Mail $mail) {
|
||||||
|
$mail->subject = str_replace('Invoice #', 'Invoice ***', $mail->subject);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Outgoing Request Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\OutgoingRequest;
|
||||||
|
|
||||||
|
Nightwatch::redactOutgoingRequests(function (OutgoingRequest $outgoingRequest) {
|
||||||
|
$outgoingRequest->url = preg_replace('/api_key=\w+/', 'api_key=***', $outgoingRequest->url);
|
||||||
|
});
|
||||||
|
```
|
||||||
108
.agents/skills/configure-nightwatch/reference.md
Normal file
108
.agents/skills/configure-nightwatch/reference.md
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
# Nightwatch Configuration Reference
|
||||||
|
|
||||||
|
## Configuration Summary by Event Type
|
||||||
|
|
||||||
|
| Event Type | Sampling | Filtering | Redaction |
|
||||||
|
| --------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------- |
|
||||||
|
| **Requests** | `NIGHTWATCH_REQUEST_SAMPLE_RATE`, Route middleware | Not applicable | Headers, payload, URL, IP |
|
||||||
|
| **Commands** | `NIGHTWATCH_COMMAND_SAMPLE_RATE`, Event listener | Not applicable | Command arguments |
|
||||||
|
| **Queries** | Parent context | `rejectQueries()`, `NIGHTWATCH_IGNORE_QUERIES` | SQL statement |
|
||||||
|
| **Cache** | Parent context | `rejectCacheKeys()`, `rejectCacheEvents()`, `NIGHTWATCH_IGNORE_CACHE_EVENTS` | Cache key |
|
||||||
|
| **Jobs** | Parent context, Queue::before | `rejectQueuedJobs()` | Not applicable |
|
||||||
|
| **Mail** | Parent context | `rejectMail()`, `NIGHTWATCH_IGNORE_MAIL` | Subject |
|
||||||
|
| **Notifications** | Parent context | `rejectNotifications()`, `NIGHTWATCH_IGNORE_NOTIFICATIONS` | Not applicable |
|
||||||
|
| **Outgoing Requests** | Parent context | `rejectOutgoingRequests()`, `NIGHTWATCH_IGNORE_OUTGOING_REQUESTS` | URL |
|
||||||
|
| **Exceptions** | `NIGHTWATCH_EXCEPTION_SAMPLE_RATE` | Not applicable | Exception message |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Production Recommendations
|
||||||
|
|
||||||
|
### High-Traffic Applications
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Conservative sampling
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.01 # 1% of requests
|
||||||
|
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=0.1 # 10% of commands
|
||||||
|
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0 # Always capture exceptions
|
||||||
|
|
||||||
|
# Filter noisy events
|
||||||
|
|
||||||
|
NIGHTWATCH_IGNORE_CACHE_EVENTS=true
|
||||||
|
NIGHTWATCH_IGNORE_QUERIES=true # Or filter specific queries programmatically
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Privacy-Conscious Applications
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Disable sensitive data collection
|
||||||
|
|
||||||
|
NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD=false
|
||||||
|
NIGHTWATCH_REDACT_HEADERS=Authorization,Cookie,Proxy-Authorization,X-XSRF-TOKEN
|
||||||
|
|
||||||
|
# Or use redaction in AppServiceProvider
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Balanced Configuration (Recommended Start)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Sample rates
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0
|
||||||
|
|
||||||
|
# Filter obvious noise programmatically
|
||||||
|
|
||||||
|
# Redact PII as needed
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verification Checklist
|
||||||
|
|
||||||
|
After configuration:
|
||||||
|
|
||||||
|
- [ ] Sampling rates appropriate for traffic volume
|
||||||
|
- [ ] Noisy events filtered (cache, certain queries)
|
||||||
|
- [ ] Sensitive data redacted (PII, tokens, credentials)
|
||||||
|
- [ ] Exceptions always captured for debugging
|
||||||
|
- [ ] Test in development with `NIGHTWATCH_REQUEST_SAMPLE_RATE=1.0`
|
||||||
|
- [ ] Monitor event quota usage in Nightwatch dashboard
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Common Patterns
|
||||||
|
|
||||||
|
### Filter Health Checks + Reduce Sampling
|
||||||
|
|
||||||
|
```php
|
||||||
|
Route::get('/health', fn() => ['status' => 'ok'])
|
||||||
|
->middleware(Sample::never());
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exclude Internal/Vendor Queries
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::rejectQueries(fn($q) =>
|
||||||
|
str_contains($q->sql, 'telescope') ||
|
||||||
|
str_contains($q->sql, 'pulse')
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Protect User Data in Cache Keys
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::redactCacheEvents(fn($e) =>
|
||||||
|
$e->key = preg_replace('/user:\d+/', 'user:***', $e->key)
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: fortify-development
|
name: fortify-development
|
||||||
description: 'ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.'
|
description: 'ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), passkeys, profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, passkeys, WebAuthn, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.'
|
||||||
license: MIT
|
license: MIT
|
||||||
metadata:
|
metadata:
|
||||||
author: laravel
|
author: laravel
|
||||||
|
|
@ -32,6 +32,7 @@ ## Available Features
|
||||||
- `Features::updateProfileInformation()` - Profile updates
|
- `Features::updateProfileInformation()` - Profile updates
|
||||||
- `Features::updatePasswords()` - Password changes
|
- `Features::updatePasswords()` - Password changes
|
||||||
- `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes
|
- `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes
|
||||||
|
- `Features::passkeys()` - Passwordless authentication with WebAuthn passkeys
|
||||||
|
|
||||||
> Use `search-docs` for feature configuration options and customization patterns.
|
> Use `search-docs` for feature configuration options and customization patterns.
|
||||||
|
|
||||||
|
|
@ -50,6 +51,18 @@ ### Two-Factor Authentication Setup
|
||||||
|
|
||||||
> Use `search-docs` for TOTP implementation and recovery code handling patterns.
|
> Use `search-docs` for TOTP implementation and recovery code handling patterns.
|
||||||
|
|
||||||
|
### Passkeys Setup
|
||||||
|
|
||||||
|
```
|
||||||
|
- [ ] Add PasskeyAuthenticatable trait to User model and implement PasskeyUser
|
||||||
|
- [ ] Enable passkeys feature in config/fortify.php
|
||||||
|
- [ ] If the passkeys table migration is missing, publish via `php artisan vendor:publish --tag=fortify-migrations` and migrate
|
||||||
|
- [ ] Configure passkeys relying_party_id, allowed_origins, user_handle_secret, and timeout if defaults are not suitable
|
||||||
|
- [ ] Build UI with @laravel/passkeys for registration, login, confirmation, and deletion
|
||||||
|
```
|
||||||
|
|
||||||
|
> Use `search-docs` for passkey configuration options. For `@laravel/passkeys` frontend usage, refer to the package's README on npm.
|
||||||
|
|
||||||
### Email Verification Setup
|
### Email Verification Setup
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -129,3 +142,10 @@ ## Key Endpoints
|
||||||
| 2FA Challenge | POST | `/two-factor-challenge` |
|
| 2FA Challenge | POST | `/two-factor-challenge` |
|
||||||
| Get QR Code | GET | `/user/two-factor-qr-code` |
|
| Get QR Code | GET | `/user/two-factor-qr-code` |
|
||||||
| Recovery Codes | GET/POST | `/user/two-factor-recovery-codes` |
|
| Recovery Codes | GET/POST | `/user/two-factor-recovery-codes` |
|
||||||
|
| Passkey Login Options | GET | `/passkeys/login/options` |
|
||||||
|
| Passkey Login | POST | `/passkeys/login` |
|
||||||
|
| Passkey Confirm Options| GET | `/passkeys/confirm/options` |
|
||||||
|
| Passkey Confirm | POST | `/passkeys/confirm` |
|
||||||
|
| Passkey Options | GET | `/user/passkeys/options` |
|
||||||
|
| Register Passkey | POST | `/user/passkeys` |
|
||||||
|
| Delete Passkey | DELETE | `/user/passkeys/{passkey}` |
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ ### 8. Testing Patterns → `rules/testing.md`
|
||||||
### 9. Queue & Job Patterns → `rules/queue-jobs.md`
|
### 9. Queue & Job Patterns → `rules/queue-jobs.md`
|
||||||
|
|
||||||
- `retry_after` must exceed job `timeout`; use exponential backoff `[1, 5, 10]`
|
- `retry_after` must exceed job `timeout`; use exponential backoff `[1, 5, 10]`
|
||||||
- `ShouldBeUnique` to prevent duplicates; `WithoutOverlapping::untilProcessing()` for concurrency
|
- `ShouldBeUnique` to prevent duplicates; `ShouldBeUniqueUntilProcessing` for early lock release
|
||||||
- Always implement `failed()`; with `retryUntil()`, set `$tries = 0`
|
- Always implement `failed()`; with `retryUntil()`, set `$tries = 0`
|
||||||
- `RateLimited` middleware for external API calls; `Bus::batch()` for related jobs
|
- `RateLimited` middleware for external API calls; `Bus::batch()` for related jobs
|
||||||
- Horizon for complex multi-queue scenarios
|
- Horizon for complex multi-queue scenarios
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ ## Code to Interfaces
|
||||||
|
|
||||||
## Default Sort by Descending
|
## Default Sort by Descending
|
||||||
|
|
||||||
When no explicit order is specified, sort by `id` or `created_at` descending. Explicit ordering prevents cross-database inconsistencies between MySQL and Postgres.
|
When no explicit order is specified, sort by `id` or `created_at` descending. Without an explicit `ORDER BY`, row order is undefined.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ # Caching Best Practices
|
||||||
|
|
||||||
## Use `Cache::remember()` Instead of Manual Get/Put
|
## Use `Cache::remember()` Instead of Manual Get/Put
|
||||||
|
|
||||||
Atomic pattern prevents race conditions and removes boilerplate.
|
Cleaner cache-aside pattern that removes boilerplate. use `Cache::lock()` for race conditions.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ # Configuration Best Practices
|
||||||
|
|
||||||
## `env()` Only in Config Files
|
## `env()` Only in Config Files
|
||||||
|
|
||||||
Direct `env()` calls return `null` when config is cached.
|
Direct `env()` calls may return `null` when config is cached.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,11 @@ ## Always Queue Notifications
|
||||||
|
|
||||||
## Use `afterCommit()` on Notifications in Transactions
|
## Use `afterCommit()` on Notifications in Transactions
|
||||||
|
|
||||||
Same race condition as events — the queued notification job may run before the transaction commits.
|
Same race condition as events — call `afterCommit()` to delay dispatch until the transaction commits.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$user->notify((new InvoicePaid($invoice))->afterCommit());
|
||||||
|
```
|
||||||
|
|
||||||
## Route Notification Channels to Dedicated Queues
|
## Route Notification Channels to Dedicated Queues
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ ## Use Retry with Backoff for External APIs
|
||||||
Only retry on specific errors:
|
Only retry on specific errors:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$response = Http::retry(3, 100, function (Exception $exception, PendingRequest $request) {
|
$response = Http::retry(3, 100, function (Throwable $exception, PendingRequest $request) {
|
||||||
return $exception instanceof ConnectionException
|
return $exception instanceof ConnectionException
|
||||||
|| ($exception instanceof RequestException && $exception->response->serverError());
|
|| ($exception instanceof RequestException && $exception->response->serverError());
|
||||||
})->post('https://api.example.com/data');
|
})->post('https://api.example.com/data');
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ ## Use `afterCommit()` on Mailables Inside Transactions
|
||||||
|
|
||||||
## Use `assertQueued()` Not `assertSent()` for Queued Mailables
|
## Use `assertQueued()` Not `assertSent()` for Queued Mailables
|
||||||
|
|
||||||
`Mail::assertSent()` only catches synchronous mail. Queued mailables silently pass `assertSent`, giving false confidence.
|
`Mail::assertSent()` only catches synchronous mail. Queued mailables fail `assertSent` with a "Did you mean to use assertQueued()?" hint.
|
||||||
|
|
||||||
Incorrect: `Mail::assertSent(OrderShipped::class);` when mailable implements `ShouldQueue`.
|
Incorrect: `Mail::assertSent(OrderShipped::class);` when mailable implements `ShouldQueue`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,25 +106,23 @@ ## `retryUntil()` Needs `$tries = 0`
|
||||||
```php
|
```php
|
||||||
public $tries = 0;
|
public $tries = 0;
|
||||||
|
|
||||||
public function retryUntil(): DateTime
|
public function retryUntil(): \DateTimeInterface
|
||||||
{
|
{
|
||||||
return now()->addHours(4);
|
return now()->addHours(4);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use `WithoutOverlapping::untilProcessing()`
|
## Use `ShouldBeUniqueUntilProcessing` for Early Lock Release
|
||||||
|
|
||||||
Prevents concurrent execution while allowing new instances to queue.
|
`ShouldBeUnique` holds the lock until the job completes. `ShouldBeUniqueUntilProcessing` releases it when processing starts, allowing new instances to queue.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function middleware(): array
|
class UpdateSearchIndex implements ShouldQueue, ShouldBeUniqueUntilProcessing
|
||||||
{
|
{
|
||||||
return [new WithoutOverlapping($this->product->id)->untilProcessing()];
|
// Lock releases when processing begins, not when it finishes
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Without `untilProcessing()`, the lock extends through queue wait time. With it, the lock releases when processing starts.
|
|
||||||
|
|
||||||
## Use Horizon for Complex Queue Scenarios
|
## Use Horizon for Complex Queue Scenarios
|
||||||
|
|
||||||
Use Laravel Horizon when you need monitoring, auto-scaling, failure tracking, or multiple queues with different priorities.
|
Use Laravel Horizon when you need monitoring, auto-scaling, failure tracking, or multiple queues with different priorities.
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ ## Use Resource Controllers
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Route::resource('posts', PostController::class);
|
Route::resource('posts', PostController::class);
|
||||||
Route::apiResource('api/posts', Api\PostController::class);
|
// In routes/api.php — the /api prefix is applied automatically
|
||||||
|
Route::apiResource('posts', Api\PostController::class);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Keep Controllers Thin
|
## Keep Controllers Thin
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ ## Authorize Every Action
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
public function update(Request $request, Post $post)
|
public function update(UpdatePostRequest $request, Post $post)
|
||||||
{
|
{
|
||||||
$post->update($request->validated());
|
$post->update($request->validated());
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ ## Escape Output to Prevent XSS
|
||||||
|
|
||||||
## CSRF Protection
|
## CSRF Protection
|
||||||
|
|
||||||
Include `@csrf` in all POST/PUT/DELETE Blade forms. Not needed in Inertia.
|
Include `@csrf` in all POST/PUT/DELETE Blade forms. In Inertia apps, the `@csrf` directive is automatically applied.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```blade
|
```blade
|
||||||
|
|
@ -121,7 +121,7 @@ ## Rate Limit Auth and API Routes
|
||||||
|
|
||||||
## Validate File Uploads
|
## Validate File Uploads
|
||||||
|
|
||||||
Validate MIME type, extension, and size. Never trust client-provided filenames.
|
Validate extension, MIME type, and size. The `mimes` rule checks extensions; use `mimetypes` for actual MIME type validation. Never trust client-provided filenames.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -2,7 +2,7 @@ # Testing Best Practices
|
||||||
|
|
||||||
## Use `LazilyRefreshDatabase` Over `RefreshDatabase`
|
## Use `LazilyRefreshDatabase` Over `RefreshDatabase`
|
||||||
|
|
||||||
`RefreshDatabase` runs all migrations every test run even when the schema hasn't changed. `LazilyRefreshDatabase` only migrates when needed, significantly speeding up large suites.
|
`RefreshDatabase` migrates once per process and wraps each test in a rolled-back transaction. `LazilyRefreshDatabase` skips even that first migration if the schema is already up to date.
|
||||||
|
|
||||||
## Use Model Assertions Over Raw Database Assertions
|
## Use Model Assertions Over Raw Database Assertions
|
||||||
|
|
||||||
|
|
|
||||||
96
.agents/skills/mcp-development/SKILL.md
Normal file
96
.agents/skills/mcp-development/SKILL.md
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
---
|
||||||
|
name: mcp-development
|
||||||
|
description: "Use this skill for Laravel MCP development only. Trigger when creating or editing MCP tools, resources, prompts, or servers in Laravel projects. Covers: artisan make:mcp-* generators, mcp:inspector, routes/ai.php, Tool/Resource/Prompt classes, schema validation, shouldRegister(), OAuth setup, URI templates, read-only attributes, and MCP debugging. Do not use for non-Laravel MCP projects or generic AI features without MCP."
|
||||||
|
license: MIT
|
||||||
|
metadata:
|
||||||
|
author: laravel
|
||||||
|
---
|
||||||
|
|
||||||
|
# MCP Development
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Use `search-docs` for detailed Laravel MCP patterns and documentation.
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
Register MCP servers in `routes/ai.php`:
|
||||||
|
|
||||||
|
<!-- Register MCP Server -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Facades\Mcp;
|
||||||
|
|
||||||
|
Mcp::web();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating MCP Primitives
|
||||||
|
|
||||||
|
Create MCP tools, resources, prompts, and servers using artisan commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan make:mcp-tool ToolName # Create a tool
|
||||||
|
|
||||||
|
php artisan make:mcp-resource ResourceName # Create a resource
|
||||||
|
|
||||||
|
php artisan make:mcp-prompt PromptName # Create a prompt
|
||||||
|
|
||||||
|
php artisan make:mcp-server ServerName # Create a server
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
After creating primitives, register them in your server's `$tools`, `$resources`, or `$prompts` properties.
|
||||||
|
|
||||||
|
### Tools
|
||||||
|
|
||||||
|
<!-- MCP Tool Example -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Server\Tool;
|
||||||
|
use Laravel\Mcp\Server\Request;
|
||||||
|
use Laravel\Mcp\Server\Response;
|
||||||
|
|
||||||
|
class MyTool extends Tool
|
||||||
|
{
|
||||||
|
public function handle(Request $request): Response
|
||||||
|
{
|
||||||
|
return new Response(['result' => 'success']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Registering Primitives in a Server
|
||||||
|
|
||||||
|
Each MCP server must explicitly declare the tools, resources, and prompts it exposes.
|
||||||
|
|
||||||
|
<!-- Register Primitives in MCP Server -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Server;
|
||||||
|
|
||||||
|
class AppServer extends Server
|
||||||
|
{
|
||||||
|
protected array $tools = [
|
||||||
|
\App\Mcp\Tools\MyTool::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected array $resources = [
|
||||||
|
\App\Mcp\Resources\MyResource::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected array $prompts = [
|
||||||
|
\App\Mcp\Prompts\MyPrompt::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
1. Check `routes/ai.php` for proper registration
|
||||||
|
2. Test tool via MCP client
|
||||||
|
|
||||||
|
## Common Pitfalls
|
||||||
|
|
||||||
|
- Running `mcp:start` command (it hangs waiting for input)
|
||||||
|
- Using HTTPS locally with Node-based MCP clients
|
||||||
|
- Not using `search-docs` for the latest MCP documentation
|
||||||
|
- Not registering MCP server routes in `routes/ai.php`
|
||||||
|
- Do not register `ai.php` in `bootstrap.php`; it is registered automatically.
|
||||||
|
- OAuth registration supports custom URI schemes (e.g., `cursor://`, `vscode://`) for native desktop clients via `mcp.custom_schemes` config
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: pest-testing
|
name: pest-testing
|
||||||
description: "Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code."
|
description: "Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: test()/it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code."
|
||||||
license: MIT
|
license: MIT
|
||||||
metadata:
|
metadata:
|
||||||
author: laravel
|
author: laravel
|
||||||
|
|
@ -18,6 +18,12 @@ ### Creating Tests
|
||||||
|
|
||||||
All tests must be written using Pest. Use `php artisan make:test --pest {name}`.
|
All tests must be written using Pest. Use `php artisan make:test --pest {name}`.
|
||||||
|
|
||||||
|
The `{name}` argument should include only the path and test name, but should not include the test suite.
|
||||||
|
- Incorrect: `php artisan make:test --pest Feature/SomeFeatureTest` will generate `tests/Feature/Feature/SomeFeatureTest.php`
|
||||||
|
- Correct: `php artisan make:test --pest SomeControllerTest` will generate `tests/Feature/SomeControllerTest.php`
|
||||||
|
- Incorrect: `php artisan make:test --pest --unit Unit/SomeServiceTest` will generate `tests/Unit/Unit/SomeServiceTest.php`
|
||||||
|
- Correct: `php artisan make:test --pest --unit SomeServiceTest` will generate `tests/Unit/SomeServiceTest.php`
|
||||||
|
|
||||||
### Test Organization
|
### Test Organization
|
||||||
|
|
||||||
- Unit/Feature tests: `tests/Feature` and `tests/Unit` directories.
|
- Unit/Feature tests: `tests/Feature` and `tests/Unit` directories.
|
||||||
|
|
@ -26,6 +32,8 @@ ### Test Organization
|
||||||
|
|
||||||
### Basic Test Structure
|
### Basic Test Structure
|
||||||
|
|
||||||
|
Pest supports both `test()` and `it()` functions. Before writing new tests, check existing test files in the same directory to match the project's convention. Use `test()` if existing tests use `test()`, or `it()` if they use `it()`.
|
||||||
|
|
||||||
<!-- Basic Pest Test Example -->
|
<!-- Basic Pest Test Example -->
|
||||||
```php
|
```php
|
||||||
it('is true', function () {
|
it('is true', function () {
|
||||||
|
|
@ -155,3 +163,4 @@ ## Common Pitfalls
|
||||||
- Forgetting datasets for repetitive validation tests
|
- Forgetting datasets for repetitive validation tests
|
||||||
- Deleting tests without approval
|
- Deleting tests without approval
|
||||||
- Forgetting `assertNoJavaScriptErrors()` in browser tests
|
- Forgetting `assertNoJavaScriptErrors()` in browser tests
|
||||||
|
- Prefixing `Feature/` or `Unit/` in `{name}` when using `make:test`
|
||||||
|
|
|
||||||
404
.claude/skills/configure-nightwatch/SKILL.md
Normal file
404
.claude/skills/configure-nightwatch/SKILL.md
Normal file
|
|
@ -0,0 +1,404 @@
|
||||||
|
---
|
||||||
|
name: configure-nightwatch
|
||||||
|
description: Configures Laravel Nightwatch data collection, sampling rates, filtering rules, and redaction policies. Use when setting up Nightwatch, managing data volume, protecting sensitive data (PII), or optimizing event collection for production workloads.
|
||||||
|
license: MIT
|
||||||
|
metadata:
|
||||||
|
author: laravel
|
||||||
|
---
|
||||||
|
|
||||||
|
# Nightwatch Configuration Guide
|
||||||
|
|
||||||
|
This skill helps configure Laravel Nightwatch data collection to balance observability, performance, and privacy. Covers sampling strategies, filtering rules, and redaction methods across all event types.
|
||||||
|
|
||||||
|
## Documentation Reference
|
||||||
|
|
||||||
|
The [Nightwatch Documentation](https://nightwatch.laravel.com/docs) is the definitive and up-to-date source of information for all Nightwatch configuration options. This skill provides practical guidance and common patterns, but always consult the official documentation as the primary source of truth for specific details, environment variables, and API behavior. The documentation includes comprehensive coverage of:
|
||||||
|
|
||||||
|
- [Filtering and Configuration](https://nightwatch.laravel.com/docs/filtering) - Core concepts for sampling, filtering, and redaction
|
||||||
|
- Individual event type pages with specific configuration options:
|
||||||
|
- [Requests](https://nightwatch.laravel.com/docs/requests) - Request sampling, header handling, payload capture
|
||||||
|
- [Commands](https://nightwatch.laravel.com/docs/commands) - Command sampling and redaction
|
||||||
|
- [Queries](https://nightwatch.laravel.com/docs/queries) - Query filtering and redaction
|
||||||
|
- [Cache](https://nightwatch.laravel.com/docs/cache) - Cache event filtering by key or pattern
|
||||||
|
- [Jobs](https://nightwatch.laravel.com/docs/jobs) - Job filtering and sampling decoupling
|
||||||
|
- [Mail](https://nightwatch.laravel.com/docs/mail) - Mail event filtering
|
||||||
|
- [Notifications](https://nightwatch.laravel.com/docs/notifications) - Notification filtering by channel
|
||||||
|
- [Exceptions](https://nightwatch.laravel.com/docs/exceptions) - Exception sampling and throttling
|
||||||
|
- [Outgoing Requests](https://nightwatch.laravel.com/docs/outgoing-requests) - HTTP request filtering
|
||||||
|
- [reference.md](reference.md) - Quick lookup table by event type, production presets, and verification checklist
|
||||||
|
|
||||||
|
## Data Collection Flow
|
||||||
|
|
||||||
|
Nightwatch processes events through three stages:
|
||||||
|
|
||||||
|
1. **Sampling** - Controls which entry points are captured (requests, commands, scheduled tasks)
|
||||||
|
2. **Filtering** - Excludes specific events after sampling (queries, cache, mail, etc.)
|
||||||
|
3. **Redaction** - Modifies captured data to remove/obfuscate sensitive information
|
||||||
|
|
||||||
|
```
|
||||||
|
Request/Command/Scheduled Task
|
||||||
|
|
|
||||||
|
v
|
||||||
|
[Sampling?] ----NO----> Drop entire trace
|
||||||
|
| YES
|
||||||
|
v
|
||||||
|
Events generated
|
||||||
|
|
|
||||||
|
v
|
||||||
|
[Filtering?] ----YES---> Drop specific event
|
||||||
|
| NO
|
||||||
|
v
|
||||||
|
[Redaction] ----------> Store modified data
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sampling Configuration
|
||||||
|
|
||||||
|
Sampling determines which entry points (requests, commands, scheduled tasks) trigger full trace collection. When an entry point is sampled, all related events are captured.
|
||||||
|
|
||||||
|
### Global Sample Rates
|
||||||
|
|
||||||
|
Configure via environment variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Default: 100% sampling (all requests/commands captured)
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1 # Recommended: 10% of requests
|
||||||
|
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0 # Capture all commands
|
||||||
|
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0 # Always capture exceptions
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**Recommendation**: Start with `0.1` (10%) for requests in production, adjust based on volume and needs.
|
||||||
|
|
||||||
|
### Route-Based Sampling
|
||||||
|
|
||||||
|
Apply different rates to specific routes using the `Sample` middleware:
|
||||||
|
|
||||||
|
```php routes/web.php
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Laravel\Nightwatch\Http\Middleware\Sample;
|
||||||
|
|
||||||
|
// Sample admin routes at 100%
|
||||||
|
Route::middleware(Sample::rate(1.0))->prefix('admin')->group(function () {
|
||||||
|
// All admin routes sampled fully
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sample API routes at 5%
|
||||||
|
Route::middleware(Sample::rate(0.05))->prefix('api')->group(function () {
|
||||||
|
// API routes sampled sparingly
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always sample critical endpoints
|
||||||
|
Route::post('/checkout', [CheckoutController::class, 'process'])
|
||||||
|
->middleware(Sample::always());
|
||||||
|
|
||||||
|
// Never sample health checks
|
||||||
|
Route::get('/health', [HealthController::class, 'check'])
|
||||||
|
->middleware(Sample::never());
|
||||||
|
```
|
||||||
|
|
||||||
|
### Unmatched Route Sampling
|
||||||
|
|
||||||
|
Handle 404/bot traffic with reduced sampling:
|
||||||
|
|
||||||
|
```php routes/web.php
|
||||||
|
Route::fallback(fn () => abort(404))
|
||||||
|
->middleware(Sample::rate(0.01)); // 1% sampling for unmatched routes
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dynamic Sampling
|
||||||
|
|
||||||
|
Sample based on runtime conditions (user role, request attributes):
|
||||||
|
|
||||||
|
```php app/Http/Middleware/SampleAdminRequests.php
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
|
||||||
|
class SampleAdminRequests
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
if ($request->user()?->isAdmin()) {
|
||||||
|
Nightwatch::sample(); // Always sample admin requests
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command Sampling
|
||||||
|
|
||||||
|
Exclude specific commands from sampling:
|
||||||
|
|
||||||
|
```php AppServiceProvider.php
|
||||||
|
use Illuminate\Console\Events\CommandStarting;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Event::listen(function (CommandStarting $event) {
|
||||||
|
if (in_array($event->command, ['schedule:finish', 'horizon:snapshot'])) {
|
||||||
|
Nightwatch::dontSample();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vendor Commands
|
||||||
|
|
||||||
|
Nightwatch automatically ignores framework/internal commands. Opt-in to capture them:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::captureDefaultVendorCommands();
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Filtering Configuration
|
||||||
|
|
||||||
|
Filtering excludes specific events from collection after sampling. Use filtering to reduce noise and quota usage.
|
||||||
|
|
||||||
|
### Database Queries
|
||||||
|
|
||||||
|
**Filter all queries** (disable query collection):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_QUERIES=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter specific queries** by SQL pattern:
|
||||||
|
|
||||||
|
```php AppServiceProvider.php
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
use Laravel\Nightwatch\Records\Query;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
// Filter job table queries (PostgreSQL)
|
||||||
|
Nightwatch::rejectQueries(function (Query $query) {
|
||||||
|
return str_contains($query->sql, 'into "jobs"');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter cache table queries (MySQL)
|
||||||
|
Nightwatch::rejectQueries(function (Query $query) {
|
||||||
|
return str_contains($query->sql, 'from `cache`')
|
||||||
|
|| str_contains($query->sql, 'into `cache`');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cache Events
|
||||||
|
|
||||||
|
**Filter all cache events**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_CACHE_EVENTS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by cache key patterns**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::rejectCacheKeys([
|
||||||
|
'my-app:users', // Exact match
|
||||||
|
'/^my-app:posts:/', // Regex: starts with my-app:posts:
|
||||||
|
'/^[a-zA-Z0-9]{40}$/', // Regex: session IDs
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter with callback**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\CacheEvent;
|
||||||
|
|
||||||
|
Nightwatch::rejectCacheEvents(function (CacheEvent $cacheEvent) {
|
||||||
|
return str_starts_with($cacheEvent->key, 'temp:');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mail Events
|
||||||
|
|
||||||
|
**Filter all mail**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_MAIL=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter specific mail**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Mail;
|
||||||
|
|
||||||
|
Nightwatch::rejectMail(function (Mail $mail) {
|
||||||
|
return str_contains($mail->subject, 'Newsletter');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Notification Events
|
||||||
|
|
||||||
|
**Filter all notifications**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_NOTIFICATIONS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by channel**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Notification;
|
||||||
|
|
||||||
|
Nightwatch::rejectNotifications(function (Notification $notification) {
|
||||||
|
return $notification->channel === 'database';
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Outgoing HTTP Requests
|
||||||
|
|
||||||
|
**Filter all outgoing requests**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_OUTGOING_REQUESTS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by URL**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\OutgoingRequest;
|
||||||
|
|
||||||
|
Nightwatch::rejectOutgoingRequests(function (OutgoingRequest $request) {
|
||||||
|
return str_contains($request->url, 'analytics.example.com');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Queued Jobs
|
||||||
|
|
||||||
|
**Filter specific jobs**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\QueuedJob;
|
||||||
|
|
||||||
|
Nightwatch::rejectQueuedJobs(function (QueuedJob $job) {
|
||||||
|
return $job->name === 'App\Jobs\LowPriorityJob';
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Decoupling Job Sampling
|
||||||
|
|
||||||
|
Sample jobs independently from parent contexts:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Illuminate\Support\Facades\Queue;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Queue::before(fn () => Nightwatch::sample(rate: 0.5));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Redaction Configuration
|
||||||
|
|
||||||
|
Redaction modifies captured data to remove or obfuscate sensitive information. Unlike filtering, redaction keeps the event but sanitizes its content.
|
||||||
|
|
||||||
|
### Request Redaction
|
||||||
|
|
||||||
|
**Redact sensitive headers** (automatically redacts: Authorization, Cookie, X-XSRF-TOKEN):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Customize redacted headers
|
||||||
|
|
||||||
|
NIGHTWATCH_REDACT_HEADERS=Authorization,Cookie,Proxy-Authorization,X-API-Key
|
||||||
|
```
|
||||||
|
|
||||||
|
**Redact request payloads** (disabled by default):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Enable payload capture
|
||||||
|
|
||||||
|
NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD=true
|
||||||
|
|
||||||
|
# Customize redacted fields
|
||||||
|
|
||||||
|
NIGHTWATCH_REDACT_PAYLOAD_FIELDS=password,password_confirmation,ssn,credit_card
|
||||||
|
```
|
||||||
|
|
||||||
|
**Programmatic redaction**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
use Laravel\Nightwatch\Records\Request;
|
||||||
|
|
||||||
|
Nightwatch::redactRequests(function (Request $request) {
|
||||||
|
$request->url = str_replace('secret', '***', $request->url);
|
||||||
|
$request->ip = preg_replace('/\d+$/', '***', $request->ip);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Query Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Query;
|
||||||
|
|
||||||
|
Nightwatch::redactQueries(function (Query $query) {
|
||||||
|
$query->sql = str_replace('secret_token', '***', $query->sql);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cache Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\CacheEvent;
|
||||||
|
|
||||||
|
Nightwatch::redactCacheEvents(function (CacheEvent $cacheEvent) {
|
||||||
|
$cacheEvent->key = str_replace('user:', 'user:***:', $cacheEvent->key);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Command;
|
||||||
|
|
||||||
|
Nightwatch::redactCommands(function (Command $command) {
|
||||||
|
$command->command = preg_replace('/--password=\S+/', '--password=***', $command->command);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exception Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Exception;
|
||||||
|
|
||||||
|
Nightwatch::redactExceptions(function (Exception $exception) {
|
||||||
|
$exception->message = str_replace('secret', '***', $exception->message);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mail Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Mail;
|
||||||
|
|
||||||
|
Nightwatch::redactMail(function (Mail $mail) {
|
||||||
|
$mail->subject = str_replace('Invoice #', 'Invoice ***', $mail->subject);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Outgoing Request Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\OutgoingRequest;
|
||||||
|
|
||||||
|
Nightwatch::redactOutgoingRequests(function (OutgoingRequest $outgoingRequest) {
|
||||||
|
$outgoingRequest->url = preg_replace('/api_key=\w+/', 'api_key=***', $outgoingRequest->url);
|
||||||
|
});
|
||||||
|
```
|
||||||
108
.claude/skills/configure-nightwatch/reference.md
Normal file
108
.claude/skills/configure-nightwatch/reference.md
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
# Nightwatch Configuration Reference
|
||||||
|
|
||||||
|
## Configuration Summary by Event Type
|
||||||
|
|
||||||
|
| Event Type | Sampling | Filtering | Redaction |
|
||||||
|
| --------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------- |
|
||||||
|
| **Requests** | `NIGHTWATCH_REQUEST_SAMPLE_RATE`, Route middleware | Not applicable | Headers, payload, URL, IP |
|
||||||
|
| **Commands** | `NIGHTWATCH_COMMAND_SAMPLE_RATE`, Event listener | Not applicable | Command arguments |
|
||||||
|
| **Queries** | Parent context | `rejectQueries()`, `NIGHTWATCH_IGNORE_QUERIES` | SQL statement |
|
||||||
|
| **Cache** | Parent context | `rejectCacheKeys()`, `rejectCacheEvents()`, `NIGHTWATCH_IGNORE_CACHE_EVENTS` | Cache key |
|
||||||
|
| **Jobs** | Parent context, Queue::before | `rejectQueuedJobs()` | Not applicable |
|
||||||
|
| **Mail** | Parent context | `rejectMail()`, `NIGHTWATCH_IGNORE_MAIL` | Subject |
|
||||||
|
| **Notifications** | Parent context | `rejectNotifications()`, `NIGHTWATCH_IGNORE_NOTIFICATIONS` | Not applicable |
|
||||||
|
| **Outgoing Requests** | Parent context | `rejectOutgoingRequests()`, `NIGHTWATCH_IGNORE_OUTGOING_REQUESTS` | URL |
|
||||||
|
| **Exceptions** | `NIGHTWATCH_EXCEPTION_SAMPLE_RATE` | Not applicable | Exception message |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Production Recommendations
|
||||||
|
|
||||||
|
### High-Traffic Applications
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Conservative sampling
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.01 # 1% of requests
|
||||||
|
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=0.1 # 10% of commands
|
||||||
|
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0 # Always capture exceptions
|
||||||
|
|
||||||
|
# Filter noisy events
|
||||||
|
|
||||||
|
NIGHTWATCH_IGNORE_CACHE_EVENTS=true
|
||||||
|
NIGHTWATCH_IGNORE_QUERIES=true # Or filter specific queries programmatically
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Privacy-Conscious Applications
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Disable sensitive data collection
|
||||||
|
|
||||||
|
NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD=false
|
||||||
|
NIGHTWATCH_REDACT_HEADERS=Authorization,Cookie,Proxy-Authorization,X-XSRF-TOKEN
|
||||||
|
|
||||||
|
# Or use redaction in AppServiceProvider
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Balanced Configuration (Recommended Start)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Sample rates
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0
|
||||||
|
|
||||||
|
# Filter obvious noise programmatically
|
||||||
|
|
||||||
|
# Redact PII as needed
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verification Checklist
|
||||||
|
|
||||||
|
After configuration:
|
||||||
|
|
||||||
|
- [ ] Sampling rates appropriate for traffic volume
|
||||||
|
- [ ] Noisy events filtered (cache, certain queries)
|
||||||
|
- [ ] Sensitive data redacted (PII, tokens, credentials)
|
||||||
|
- [ ] Exceptions always captured for debugging
|
||||||
|
- [ ] Test in development with `NIGHTWATCH_REQUEST_SAMPLE_RATE=1.0`
|
||||||
|
- [ ] Monitor event quota usage in Nightwatch dashboard
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Common Patterns
|
||||||
|
|
||||||
|
### Filter Health Checks + Reduce Sampling
|
||||||
|
|
||||||
|
```php
|
||||||
|
Route::get('/health', fn() => ['status' => 'ok'])
|
||||||
|
->middleware(Sample::never());
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exclude Internal/Vendor Queries
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::rejectQueries(fn($q) =>
|
||||||
|
str_contains($q->sql, 'telescope') ||
|
||||||
|
str_contains($q->sql, 'pulse')
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Protect User Data in Cache Keys
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::redactCacheEvents(fn($e) =>
|
||||||
|
$e->key = preg_replace('/user:\d+/', 'user:***', $e->key)
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: fortify-development
|
name: fortify-development
|
||||||
description: 'ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.'
|
description: 'ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), passkeys, profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, passkeys, WebAuthn, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.'
|
||||||
license: MIT
|
license: MIT
|
||||||
metadata:
|
metadata:
|
||||||
author: laravel
|
author: laravel
|
||||||
|
|
@ -32,6 +32,7 @@ ## Available Features
|
||||||
- `Features::updateProfileInformation()` - Profile updates
|
- `Features::updateProfileInformation()` - Profile updates
|
||||||
- `Features::updatePasswords()` - Password changes
|
- `Features::updatePasswords()` - Password changes
|
||||||
- `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes
|
- `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes
|
||||||
|
- `Features::passkeys()` - Passwordless authentication with WebAuthn passkeys
|
||||||
|
|
||||||
> Use `search-docs` for feature configuration options and customization patterns.
|
> Use `search-docs` for feature configuration options and customization patterns.
|
||||||
|
|
||||||
|
|
@ -50,6 +51,18 @@ ### Two-Factor Authentication Setup
|
||||||
|
|
||||||
> Use `search-docs` for TOTP implementation and recovery code handling patterns.
|
> Use `search-docs` for TOTP implementation and recovery code handling patterns.
|
||||||
|
|
||||||
|
### Passkeys Setup
|
||||||
|
|
||||||
|
```
|
||||||
|
- [ ] Add PasskeyAuthenticatable trait to User model and implement PasskeyUser
|
||||||
|
- [ ] Enable passkeys feature in config/fortify.php
|
||||||
|
- [ ] If the passkeys table migration is missing, publish via `php artisan vendor:publish --tag=fortify-migrations` and migrate
|
||||||
|
- [ ] Configure passkeys relying_party_id, allowed_origins, user_handle_secret, and timeout if defaults are not suitable
|
||||||
|
- [ ] Build UI with @laravel/passkeys for registration, login, confirmation, and deletion
|
||||||
|
```
|
||||||
|
|
||||||
|
> Use `search-docs` for passkey configuration options. For `@laravel/passkeys` frontend usage, refer to the package's README on npm.
|
||||||
|
|
||||||
### Email Verification Setup
|
### Email Verification Setup
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -129,3 +142,10 @@ ## Key Endpoints
|
||||||
| 2FA Challenge | POST | `/two-factor-challenge` |
|
| 2FA Challenge | POST | `/two-factor-challenge` |
|
||||||
| Get QR Code | GET | `/user/two-factor-qr-code` |
|
| Get QR Code | GET | `/user/two-factor-qr-code` |
|
||||||
| Recovery Codes | GET/POST | `/user/two-factor-recovery-codes` |
|
| Recovery Codes | GET/POST | `/user/two-factor-recovery-codes` |
|
||||||
|
| Passkey Login Options | GET | `/passkeys/login/options` |
|
||||||
|
| Passkey Login | POST | `/passkeys/login` |
|
||||||
|
| Passkey Confirm Options| GET | `/passkeys/confirm/options` |
|
||||||
|
| Passkey Confirm | POST | `/passkeys/confirm` |
|
||||||
|
| Passkey Options | GET | `/user/passkeys/options` |
|
||||||
|
| Register Passkey | POST | `/user/passkeys` |
|
||||||
|
| Delete Passkey | DELETE | `/user/passkeys/{passkey}` |
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ ### 8. Testing Patterns → `rules/testing.md`
|
||||||
### 9. Queue & Job Patterns → `rules/queue-jobs.md`
|
### 9. Queue & Job Patterns → `rules/queue-jobs.md`
|
||||||
|
|
||||||
- `retry_after` must exceed job `timeout`; use exponential backoff `[1, 5, 10]`
|
- `retry_after` must exceed job `timeout`; use exponential backoff `[1, 5, 10]`
|
||||||
- `ShouldBeUnique` to prevent duplicates; `WithoutOverlapping::untilProcessing()` for concurrency
|
- `ShouldBeUnique` to prevent duplicates; `ShouldBeUniqueUntilProcessing` for early lock release
|
||||||
- Always implement `failed()`; with `retryUntil()`, set `$tries = 0`
|
- Always implement `failed()`; with `retryUntil()`, set `$tries = 0`
|
||||||
- `RateLimited` middleware for external API calls; `Bus::batch()` for related jobs
|
- `RateLimited` middleware for external API calls; `Bus::batch()` for related jobs
|
||||||
- Horizon for complex multi-queue scenarios
|
- Horizon for complex multi-queue scenarios
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ ## Code to Interfaces
|
||||||
|
|
||||||
## Default Sort by Descending
|
## Default Sort by Descending
|
||||||
|
|
||||||
When no explicit order is specified, sort by `id` or `created_at` descending. Explicit ordering prevents cross-database inconsistencies between MySQL and Postgres.
|
When no explicit order is specified, sort by `id` or `created_at` descending. Without an explicit `ORDER BY`, row order is undefined.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ # Caching Best Practices
|
||||||
|
|
||||||
## Use `Cache::remember()` Instead of Manual Get/Put
|
## Use `Cache::remember()` Instead of Manual Get/Put
|
||||||
|
|
||||||
Atomic pattern prevents race conditions and removes boilerplate.
|
Cleaner cache-aside pattern that removes boilerplate. use `Cache::lock()` for race conditions.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ # Configuration Best Practices
|
||||||
|
|
||||||
## `env()` Only in Config Files
|
## `env()` Only in Config Files
|
||||||
|
|
||||||
Direct `env()` calls return `null` when config is cached.
|
Direct `env()` calls may return `null` when config is cached.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,11 @@ ## Always Queue Notifications
|
||||||
|
|
||||||
## Use `afterCommit()` on Notifications in Transactions
|
## Use `afterCommit()` on Notifications in Transactions
|
||||||
|
|
||||||
Same race condition as events — the queued notification job may run before the transaction commits.
|
Same race condition as events — call `afterCommit()` to delay dispatch until the transaction commits.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$user->notify((new InvoicePaid($invoice))->afterCommit());
|
||||||
|
```
|
||||||
|
|
||||||
## Route Notification Channels to Dedicated Queues
|
## Route Notification Channels to Dedicated Queues
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ ## Use Retry with Backoff for External APIs
|
||||||
Only retry on specific errors:
|
Only retry on specific errors:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$response = Http::retry(3, 100, function (Exception $exception, PendingRequest $request) {
|
$response = Http::retry(3, 100, function (Throwable $exception, PendingRequest $request) {
|
||||||
return $exception instanceof ConnectionException
|
return $exception instanceof ConnectionException
|
||||||
|| ($exception instanceof RequestException && $exception->response->serverError());
|
|| ($exception instanceof RequestException && $exception->response->serverError());
|
||||||
})->post('https://api.example.com/data');
|
})->post('https://api.example.com/data');
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ ## Use `afterCommit()` on Mailables Inside Transactions
|
||||||
|
|
||||||
## Use `assertQueued()` Not `assertSent()` for Queued Mailables
|
## Use `assertQueued()` Not `assertSent()` for Queued Mailables
|
||||||
|
|
||||||
`Mail::assertSent()` only catches synchronous mail. Queued mailables silently pass `assertSent`, giving false confidence.
|
`Mail::assertSent()` only catches synchronous mail. Queued mailables fail `assertSent` with a "Did you mean to use assertQueued()?" hint.
|
||||||
|
|
||||||
Incorrect: `Mail::assertSent(OrderShipped::class);` when mailable implements `ShouldQueue`.
|
Incorrect: `Mail::assertSent(OrderShipped::class);` when mailable implements `ShouldQueue`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,25 +106,23 @@ ## `retryUntil()` Needs `$tries = 0`
|
||||||
```php
|
```php
|
||||||
public $tries = 0;
|
public $tries = 0;
|
||||||
|
|
||||||
public function retryUntil(): DateTime
|
public function retryUntil(): \DateTimeInterface
|
||||||
{
|
{
|
||||||
return now()->addHours(4);
|
return now()->addHours(4);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use `WithoutOverlapping::untilProcessing()`
|
## Use `ShouldBeUniqueUntilProcessing` for Early Lock Release
|
||||||
|
|
||||||
Prevents concurrent execution while allowing new instances to queue.
|
`ShouldBeUnique` holds the lock until the job completes. `ShouldBeUniqueUntilProcessing` releases it when processing starts, allowing new instances to queue.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function middleware(): array
|
class UpdateSearchIndex implements ShouldQueue, ShouldBeUniqueUntilProcessing
|
||||||
{
|
{
|
||||||
return [new WithoutOverlapping($this->product->id)->untilProcessing()];
|
// Lock releases when processing begins, not when it finishes
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Without `untilProcessing()`, the lock extends through queue wait time. With it, the lock releases when processing starts.
|
|
||||||
|
|
||||||
## Use Horizon for Complex Queue Scenarios
|
## Use Horizon for Complex Queue Scenarios
|
||||||
|
|
||||||
Use Laravel Horizon when you need monitoring, auto-scaling, failure tracking, or multiple queues with different priorities.
|
Use Laravel Horizon when you need monitoring, auto-scaling, failure tracking, or multiple queues with different priorities.
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ ## Use Resource Controllers
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Route::resource('posts', PostController::class);
|
Route::resource('posts', PostController::class);
|
||||||
Route::apiResource('api/posts', Api\PostController::class);
|
// In routes/api.php — the /api prefix is applied automatically
|
||||||
|
Route::apiResource('posts', Api\PostController::class);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Keep Controllers Thin
|
## Keep Controllers Thin
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ ## Authorize Every Action
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
public function update(Request $request, Post $post)
|
public function update(UpdatePostRequest $request, Post $post)
|
||||||
{
|
{
|
||||||
$post->update($request->validated());
|
$post->update($request->validated());
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ ## Escape Output to Prevent XSS
|
||||||
|
|
||||||
## CSRF Protection
|
## CSRF Protection
|
||||||
|
|
||||||
Include `@csrf` in all POST/PUT/DELETE Blade forms. Not needed in Inertia.
|
Include `@csrf` in all POST/PUT/DELETE Blade forms. In Inertia apps, the `@csrf` directive is automatically applied.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```blade
|
```blade
|
||||||
|
|
@ -121,7 +121,7 @@ ## Rate Limit Auth and API Routes
|
||||||
|
|
||||||
## Validate File Uploads
|
## Validate File Uploads
|
||||||
|
|
||||||
Validate MIME type, extension, and size. Never trust client-provided filenames.
|
Validate extension, MIME type, and size. The `mimes` rule checks extensions; use `mimetypes` for actual MIME type validation. Never trust client-provided filenames.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -2,7 +2,7 @@ # Testing Best Practices
|
||||||
|
|
||||||
## Use `LazilyRefreshDatabase` Over `RefreshDatabase`
|
## Use `LazilyRefreshDatabase` Over `RefreshDatabase`
|
||||||
|
|
||||||
`RefreshDatabase` runs all migrations every test run even when the schema hasn't changed. `LazilyRefreshDatabase` only migrates when needed, significantly speeding up large suites.
|
`RefreshDatabase` migrates once per process and wraps each test in a rolled-back transaction. `LazilyRefreshDatabase` skips even that first migration if the schema is already up to date.
|
||||||
|
|
||||||
## Use Model Assertions Over Raw Database Assertions
|
## Use Model Assertions Over Raw Database Assertions
|
||||||
|
|
||||||
|
|
|
||||||
96
.claude/skills/mcp-development/SKILL.md
Normal file
96
.claude/skills/mcp-development/SKILL.md
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
---
|
||||||
|
name: mcp-development
|
||||||
|
description: "Use this skill for Laravel MCP development only. Trigger when creating or editing MCP tools, resources, prompts, or servers in Laravel projects. Covers: artisan make:mcp-* generators, mcp:inspector, routes/ai.php, Tool/Resource/Prompt classes, schema validation, shouldRegister(), OAuth setup, URI templates, read-only attributes, and MCP debugging. Do not use for non-Laravel MCP projects or generic AI features without MCP."
|
||||||
|
license: MIT
|
||||||
|
metadata:
|
||||||
|
author: laravel
|
||||||
|
---
|
||||||
|
|
||||||
|
# MCP Development
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Use `search-docs` for detailed Laravel MCP patterns and documentation.
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
Register MCP servers in `routes/ai.php`:
|
||||||
|
|
||||||
|
<!-- Register MCP Server -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Facades\Mcp;
|
||||||
|
|
||||||
|
Mcp::web();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating MCP Primitives
|
||||||
|
|
||||||
|
Create MCP tools, resources, prompts, and servers using artisan commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan make:mcp-tool ToolName # Create a tool
|
||||||
|
|
||||||
|
php artisan make:mcp-resource ResourceName # Create a resource
|
||||||
|
|
||||||
|
php artisan make:mcp-prompt PromptName # Create a prompt
|
||||||
|
|
||||||
|
php artisan make:mcp-server ServerName # Create a server
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
After creating primitives, register them in your server's `$tools`, `$resources`, or `$prompts` properties.
|
||||||
|
|
||||||
|
### Tools
|
||||||
|
|
||||||
|
<!-- MCP Tool Example -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Server\Tool;
|
||||||
|
use Laravel\Mcp\Server\Request;
|
||||||
|
use Laravel\Mcp\Server\Response;
|
||||||
|
|
||||||
|
class MyTool extends Tool
|
||||||
|
{
|
||||||
|
public function handle(Request $request): Response
|
||||||
|
{
|
||||||
|
return new Response(['result' => 'success']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Registering Primitives in a Server
|
||||||
|
|
||||||
|
Each MCP server must explicitly declare the tools, resources, and prompts it exposes.
|
||||||
|
|
||||||
|
<!-- Register Primitives in MCP Server -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Server;
|
||||||
|
|
||||||
|
class AppServer extends Server
|
||||||
|
{
|
||||||
|
protected array $tools = [
|
||||||
|
\App\Mcp\Tools\MyTool::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected array $resources = [
|
||||||
|
\App\Mcp\Resources\MyResource::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected array $prompts = [
|
||||||
|
\App\Mcp\Prompts\MyPrompt::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
1. Check `routes/ai.php` for proper registration
|
||||||
|
2. Test tool via MCP client
|
||||||
|
|
||||||
|
## Common Pitfalls
|
||||||
|
|
||||||
|
- Running `mcp:start` command (it hangs waiting for input)
|
||||||
|
- Using HTTPS locally with Node-based MCP clients
|
||||||
|
- Not using `search-docs` for the latest MCP documentation
|
||||||
|
- Not registering MCP server routes in `routes/ai.php`
|
||||||
|
- Do not register `ai.php` in `bootstrap.php`; it is registered automatically.
|
||||||
|
- OAuth registration supports custom URI schemes (e.g., `cursor://`, `vscode://`) for native desktop clients via `mcp.custom_schemes` config
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: pest-testing
|
name: pest-testing
|
||||||
description: "Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code."
|
description: "Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: test()/it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code."
|
||||||
license: MIT
|
license: MIT
|
||||||
metadata:
|
metadata:
|
||||||
author: laravel
|
author: laravel
|
||||||
|
|
@ -18,6 +18,12 @@ ### Creating Tests
|
||||||
|
|
||||||
All tests must be written using Pest. Use `php artisan make:test --pest {name}`.
|
All tests must be written using Pest. Use `php artisan make:test --pest {name}`.
|
||||||
|
|
||||||
|
The `{name}` argument should include only the path and test name, but should not include the test suite.
|
||||||
|
- Incorrect: `php artisan make:test --pest Feature/SomeFeatureTest` will generate `tests/Feature/Feature/SomeFeatureTest.php`
|
||||||
|
- Correct: `php artisan make:test --pest SomeControllerTest` will generate `tests/Feature/SomeControllerTest.php`
|
||||||
|
- Incorrect: `php artisan make:test --pest --unit Unit/SomeServiceTest` will generate `tests/Unit/Unit/SomeServiceTest.php`
|
||||||
|
- Correct: `php artisan make:test --pest --unit SomeServiceTest` will generate `tests/Unit/SomeServiceTest.php`
|
||||||
|
|
||||||
### Test Organization
|
### Test Organization
|
||||||
|
|
||||||
- Unit/Feature tests: `tests/Feature` and `tests/Unit` directories.
|
- Unit/Feature tests: `tests/Feature` and `tests/Unit` directories.
|
||||||
|
|
@ -26,6 +32,8 @@ ### Test Organization
|
||||||
|
|
||||||
### Basic Test Structure
|
### Basic Test Structure
|
||||||
|
|
||||||
|
Pest supports both `test()` and `it()` functions. Before writing new tests, check existing test files in the same directory to match the project's convention. Use `test()` if existing tests use `test()`, or `it()` if they use `it()`.
|
||||||
|
|
||||||
<!-- Basic Pest Test Example -->
|
<!-- Basic Pest Test Example -->
|
||||||
```php
|
```php
|
||||||
it('is true', function () {
|
it('is true', function () {
|
||||||
|
|
@ -155,3 +163,4 @@ ## Common Pitfalls
|
||||||
- Forgetting datasets for repetitive validation tests
|
- Forgetting datasets for repetitive validation tests
|
||||||
- Deleting tests without approval
|
- Deleting tests without approval
|
||||||
- Forgetting `assertNoJavaScriptErrors()` in browser tests
|
- Forgetting `assertNoJavaScriptErrors()` in browser tests
|
||||||
|
- Prefixing `Feature/` or `Unit/` in `{name}` when using `make:test`
|
||||||
|
|
|
||||||
404
.cursor/skills/configure-nightwatch/SKILL.md
Normal file
404
.cursor/skills/configure-nightwatch/SKILL.md
Normal file
|
|
@ -0,0 +1,404 @@
|
||||||
|
---
|
||||||
|
name: configure-nightwatch
|
||||||
|
description: Configures Laravel Nightwatch data collection, sampling rates, filtering rules, and redaction policies. Use when setting up Nightwatch, managing data volume, protecting sensitive data (PII), or optimizing event collection for production workloads.
|
||||||
|
license: MIT
|
||||||
|
metadata:
|
||||||
|
author: laravel
|
||||||
|
---
|
||||||
|
|
||||||
|
# Nightwatch Configuration Guide
|
||||||
|
|
||||||
|
This skill helps configure Laravel Nightwatch data collection to balance observability, performance, and privacy. Covers sampling strategies, filtering rules, and redaction methods across all event types.
|
||||||
|
|
||||||
|
## Documentation Reference
|
||||||
|
|
||||||
|
The [Nightwatch Documentation](https://nightwatch.laravel.com/docs) is the definitive and up-to-date source of information for all Nightwatch configuration options. This skill provides practical guidance and common patterns, but always consult the official documentation as the primary source of truth for specific details, environment variables, and API behavior. The documentation includes comprehensive coverage of:
|
||||||
|
|
||||||
|
- [Filtering and Configuration](https://nightwatch.laravel.com/docs/filtering) - Core concepts for sampling, filtering, and redaction
|
||||||
|
- Individual event type pages with specific configuration options:
|
||||||
|
- [Requests](https://nightwatch.laravel.com/docs/requests) - Request sampling, header handling, payload capture
|
||||||
|
- [Commands](https://nightwatch.laravel.com/docs/commands) - Command sampling and redaction
|
||||||
|
- [Queries](https://nightwatch.laravel.com/docs/queries) - Query filtering and redaction
|
||||||
|
- [Cache](https://nightwatch.laravel.com/docs/cache) - Cache event filtering by key or pattern
|
||||||
|
- [Jobs](https://nightwatch.laravel.com/docs/jobs) - Job filtering and sampling decoupling
|
||||||
|
- [Mail](https://nightwatch.laravel.com/docs/mail) - Mail event filtering
|
||||||
|
- [Notifications](https://nightwatch.laravel.com/docs/notifications) - Notification filtering by channel
|
||||||
|
- [Exceptions](https://nightwatch.laravel.com/docs/exceptions) - Exception sampling and throttling
|
||||||
|
- [Outgoing Requests](https://nightwatch.laravel.com/docs/outgoing-requests) - HTTP request filtering
|
||||||
|
- [reference.md](reference.md) - Quick lookup table by event type, production presets, and verification checklist
|
||||||
|
|
||||||
|
## Data Collection Flow
|
||||||
|
|
||||||
|
Nightwatch processes events through three stages:
|
||||||
|
|
||||||
|
1. **Sampling** - Controls which entry points are captured (requests, commands, scheduled tasks)
|
||||||
|
2. **Filtering** - Excludes specific events after sampling (queries, cache, mail, etc.)
|
||||||
|
3. **Redaction** - Modifies captured data to remove/obfuscate sensitive information
|
||||||
|
|
||||||
|
```
|
||||||
|
Request/Command/Scheduled Task
|
||||||
|
|
|
||||||
|
v
|
||||||
|
[Sampling?] ----NO----> Drop entire trace
|
||||||
|
| YES
|
||||||
|
v
|
||||||
|
Events generated
|
||||||
|
|
|
||||||
|
v
|
||||||
|
[Filtering?] ----YES---> Drop specific event
|
||||||
|
| NO
|
||||||
|
v
|
||||||
|
[Redaction] ----------> Store modified data
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sampling Configuration
|
||||||
|
|
||||||
|
Sampling determines which entry points (requests, commands, scheduled tasks) trigger full trace collection. When an entry point is sampled, all related events are captured.
|
||||||
|
|
||||||
|
### Global Sample Rates
|
||||||
|
|
||||||
|
Configure via environment variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Default: 100% sampling (all requests/commands captured)
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1 # Recommended: 10% of requests
|
||||||
|
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0 # Capture all commands
|
||||||
|
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0 # Always capture exceptions
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**Recommendation**: Start with `0.1` (10%) for requests in production, adjust based on volume and needs.
|
||||||
|
|
||||||
|
### Route-Based Sampling
|
||||||
|
|
||||||
|
Apply different rates to specific routes using the `Sample` middleware:
|
||||||
|
|
||||||
|
```php routes/web.php
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Laravel\Nightwatch\Http\Middleware\Sample;
|
||||||
|
|
||||||
|
// Sample admin routes at 100%
|
||||||
|
Route::middleware(Sample::rate(1.0))->prefix('admin')->group(function () {
|
||||||
|
// All admin routes sampled fully
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sample API routes at 5%
|
||||||
|
Route::middleware(Sample::rate(0.05))->prefix('api')->group(function () {
|
||||||
|
// API routes sampled sparingly
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always sample critical endpoints
|
||||||
|
Route::post('/checkout', [CheckoutController::class, 'process'])
|
||||||
|
->middleware(Sample::always());
|
||||||
|
|
||||||
|
// Never sample health checks
|
||||||
|
Route::get('/health', [HealthController::class, 'check'])
|
||||||
|
->middleware(Sample::never());
|
||||||
|
```
|
||||||
|
|
||||||
|
### Unmatched Route Sampling
|
||||||
|
|
||||||
|
Handle 404/bot traffic with reduced sampling:
|
||||||
|
|
||||||
|
```php routes/web.php
|
||||||
|
Route::fallback(fn () => abort(404))
|
||||||
|
->middleware(Sample::rate(0.01)); // 1% sampling for unmatched routes
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dynamic Sampling
|
||||||
|
|
||||||
|
Sample based on runtime conditions (user role, request attributes):
|
||||||
|
|
||||||
|
```php app/Http/Middleware/SampleAdminRequests.php
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
|
||||||
|
class SampleAdminRequests
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
if ($request->user()?->isAdmin()) {
|
||||||
|
Nightwatch::sample(); // Always sample admin requests
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command Sampling
|
||||||
|
|
||||||
|
Exclude specific commands from sampling:
|
||||||
|
|
||||||
|
```php AppServiceProvider.php
|
||||||
|
use Illuminate\Console\Events\CommandStarting;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Event::listen(function (CommandStarting $event) {
|
||||||
|
if (in_array($event->command, ['schedule:finish', 'horizon:snapshot'])) {
|
||||||
|
Nightwatch::dontSample();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vendor Commands
|
||||||
|
|
||||||
|
Nightwatch automatically ignores framework/internal commands. Opt-in to capture them:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::captureDefaultVendorCommands();
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Filtering Configuration
|
||||||
|
|
||||||
|
Filtering excludes specific events from collection after sampling. Use filtering to reduce noise and quota usage.
|
||||||
|
|
||||||
|
### Database Queries
|
||||||
|
|
||||||
|
**Filter all queries** (disable query collection):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_QUERIES=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter specific queries** by SQL pattern:
|
||||||
|
|
||||||
|
```php AppServiceProvider.php
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
use Laravel\Nightwatch\Records\Query;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
// Filter job table queries (PostgreSQL)
|
||||||
|
Nightwatch::rejectQueries(function (Query $query) {
|
||||||
|
return str_contains($query->sql, 'into "jobs"');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter cache table queries (MySQL)
|
||||||
|
Nightwatch::rejectQueries(function (Query $query) {
|
||||||
|
return str_contains($query->sql, 'from `cache`')
|
||||||
|
|| str_contains($query->sql, 'into `cache`');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cache Events
|
||||||
|
|
||||||
|
**Filter all cache events**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_CACHE_EVENTS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by cache key patterns**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::rejectCacheKeys([
|
||||||
|
'my-app:users', // Exact match
|
||||||
|
'/^my-app:posts:/', // Regex: starts with my-app:posts:
|
||||||
|
'/^[a-zA-Z0-9]{40}$/', // Regex: session IDs
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter with callback**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\CacheEvent;
|
||||||
|
|
||||||
|
Nightwatch::rejectCacheEvents(function (CacheEvent $cacheEvent) {
|
||||||
|
return str_starts_with($cacheEvent->key, 'temp:');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mail Events
|
||||||
|
|
||||||
|
**Filter all mail**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_MAIL=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter specific mail**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Mail;
|
||||||
|
|
||||||
|
Nightwatch::rejectMail(function (Mail $mail) {
|
||||||
|
return str_contains($mail->subject, 'Newsletter');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Notification Events
|
||||||
|
|
||||||
|
**Filter all notifications**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_NOTIFICATIONS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by channel**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Notification;
|
||||||
|
|
||||||
|
Nightwatch::rejectNotifications(function (Notification $notification) {
|
||||||
|
return $notification->channel === 'database';
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Outgoing HTTP Requests
|
||||||
|
|
||||||
|
**Filter all outgoing requests**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NIGHTWATCH_IGNORE_OUTGOING_REQUESTS=true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Filter by URL**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\OutgoingRequest;
|
||||||
|
|
||||||
|
Nightwatch::rejectOutgoingRequests(function (OutgoingRequest $request) {
|
||||||
|
return str_contains($request->url, 'analytics.example.com');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Queued Jobs
|
||||||
|
|
||||||
|
**Filter specific jobs**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\QueuedJob;
|
||||||
|
|
||||||
|
Nightwatch::rejectQueuedJobs(function (QueuedJob $job) {
|
||||||
|
return $job->name === 'App\Jobs\LowPriorityJob';
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Decoupling Job Sampling
|
||||||
|
|
||||||
|
Sample jobs independently from parent contexts:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Illuminate\Support\Facades\Queue;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Queue::before(fn () => Nightwatch::sample(rate: 0.5));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Redaction Configuration
|
||||||
|
|
||||||
|
Redaction modifies captured data to remove or obfuscate sensitive information. Unlike filtering, redaction keeps the event but sanitizes its content.
|
||||||
|
|
||||||
|
### Request Redaction
|
||||||
|
|
||||||
|
**Redact sensitive headers** (automatically redacts: Authorization, Cookie, X-XSRF-TOKEN):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Customize redacted headers
|
||||||
|
|
||||||
|
NIGHTWATCH_REDACT_HEADERS=Authorization,Cookie,Proxy-Authorization,X-API-Key
|
||||||
|
```
|
||||||
|
|
||||||
|
**Redact request payloads** (disabled by default):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Enable payload capture
|
||||||
|
|
||||||
|
NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD=true
|
||||||
|
|
||||||
|
# Customize redacted fields
|
||||||
|
|
||||||
|
NIGHTWATCH_REDACT_PAYLOAD_FIELDS=password,password_confirmation,ssn,credit_card
|
||||||
|
```
|
||||||
|
|
||||||
|
**Programmatic redaction**:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
||||||
|
use Laravel\Nightwatch\Records\Request;
|
||||||
|
|
||||||
|
Nightwatch::redactRequests(function (Request $request) {
|
||||||
|
$request->url = str_replace('secret', '***', $request->url);
|
||||||
|
$request->ip = preg_replace('/\d+$/', '***', $request->ip);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Query Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Query;
|
||||||
|
|
||||||
|
Nightwatch::redactQueries(function (Query $query) {
|
||||||
|
$query->sql = str_replace('secret_token', '***', $query->sql);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cache Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\CacheEvent;
|
||||||
|
|
||||||
|
Nightwatch::redactCacheEvents(function (CacheEvent $cacheEvent) {
|
||||||
|
$cacheEvent->key = str_replace('user:', 'user:***:', $cacheEvent->key);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Command;
|
||||||
|
|
||||||
|
Nightwatch::redactCommands(function (Command $command) {
|
||||||
|
$command->command = preg_replace('/--password=\S+/', '--password=***', $command->command);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exception Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Exception;
|
||||||
|
|
||||||
|
Nightwatch::redactExceptions(function (Exception $exception) {
|
||||||
|
$exception->message = str_replace('secret', '***', $exception->message);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mail Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\Mail;
|
||||||
|
|
||||||
|
Nightwatch::redactMail(function (Mail $mail) {
|
||||||
|
$mail->subject = str_replace('Invoice #', 'Invoice ***', $mail->subject);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Outgoing Request Redaction
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Laravel\Nightwatch\Records\OutgoingRequest;
|
||||||
|
|
||||||
|
Nightwatch::redactOutgoingRequests(function (OutgoingRequest $outgoingRequest) {
|
||||||
|
$outgoingRequest->url = preg_replace('/api_key=\w+/', 'api_key=***', $outgoingRequest->url);
|
||||||
|
});
|
||||||
|
```
|
||||||
108
.cursor/skills/configure-nightwatch/reference.md
Normal file
108
.cursor/skills/configure-nightwatch/reference.md
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
# Nightwatch Configuration Reference
|
||||||
|
|
||||||
|
## Configuration Summary by Event Type
|
||||||
|
|
||||||
|
| Event Type | Sampling | Filtering | Redaction |
|
||||||
|
| --------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------- |
|
||||||
|
| **Requests** | `NIGHTWATCH_REQUEST_SAMPLE_RATE`, Route middleware | Not applicable | Headers, payload, URL, IP |
|
||||||
|
| **Commands** | `NIGHTWATCH_COMMAND_SAMPLE_RATE`, Event listener | Not applicable | Command arguments |
|
||||||
|
| **Queries** | Parent context | `rejectQueries()`, `NIGHTWATCH_IGNORE_QUERIES` | SQL statement |
|
||||||
|
| **Cache** | Parent context | `rejectCacheKeys()`, `rejectCacheEvents()`, `NIGHTWATCH_IGNORE_CACHE_EVENTS` | Cache key |
|
||||||
|
| **Jobs** | Parent context, Queue::before | `rejectQueuedJobs()` | Not applicable |
|
||||||
|
| **Mail** | Parent context | `rejectMail()`, `NIGHTWATCH_IGNORE_MAIL` | Subject |
|
||||||
|
| **Notifications** | Parent context | `rejectNotifications()`, `NIGHTWATCH_IGNORE_NOTIFICATIONS` | Not applicable |
|
||||||
|
| **Outgoing Requests** | Parent context | `rejectOutgoingRequests()`, `NIGHTWATCH_IGNORE_OUTGOING_REQUESTS` | URL |
|
||||||
|
| **Exceptions** | `NIGHTWATCH_EXCEPTION_SAMPLE_RATE` | Not applicable | Exception message |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Production Recommendations
|
||||||
|
|
||||||
|
### High-Traffic Applications
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Conservative sampling
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.01 # 1% of requests
|
||||||
|
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=0.1 # 10% of commands
|
||||||
|
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0 # Always capture exceptions
|
||||||
|
|
||||||
|
# Filter noisy events
|
||||||
|
|
||||||
|
NIGHTWATCH_IGNORE_CACHE_EVENTS=true
|
||||||
|
NIGHTWATCH_IGNORE_QUERIES=true # Or filter specific queries programmatically
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Privacy-Conscious Applications
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Disable sensitive data collection
|
||||||
|
|
||||||
|
NIGHTWATCH_CAPTURE_REQUEST_PAYLOAD=false
|
||||||
|
NIGHTWATCH_REDACT_HEADERS=Authorization,Cookie,Proxy-Authorization,X-XSRF-TOKEN
|
||||||
|
|
||||||
|
# Or use redaction in AppServiceProvider
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Balanced Configuration (Recommended Start)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# Sample rates
|
||||||
|
|
||||||
|
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1
|
||||||
|
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
|
||||||
|
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0
|
||||||
|
|
||||||
|
# Filter obvious noise programmatically
|
||||||
|
|
||||||
|
# Redact PII as needed
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verification Checklist
|
||||||
|
|
||||||
|
After configuration:
|
||||||
|
|
||||||
|
- [ ] Sampling rates appropriate for traffic volume
|
||||||
|
- [ ] Noisy events filtered (cache, certain queries)
|
||||||
|
- [ ] Sensitive data redacted (PII, tokens, credentials)
|
||||||
|
- [ ] Exceptions always captured for debugging
|
||||||
|
- [ ] Test in development with `NIGHTWATCH_REQUEST_SAMPLE_RATE=1.0`
|
||||||
|
- [ ] Monitor event quota usage in Nightwatch dashboard
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Common Patterns
|
||||||
|
|
||||||
|
### Filter Health Checks + Reduce Sampling
|
||||||
|
|
||||||
|
```php
|
||||||
|
Route::get('/health', fn() => ['status' => 'ok'])
|
||||||
|
->middleware(Sample::never());
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exclude Internal/Vendor Queries
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::rejectQueries(fn($q) =>
|
||||||
|
str_contains($q->sql, 'telescope') ||
|
||||||
|
str_contains($q->sql, 'pulse')
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Protect User Data in Cache Keys
|
||||||
|
|
||||||
|
```php
|
||||||
|
Nightwatch::redactCacheEvents(fn($e) =>
|
||||||
|
$e->key = preg_replace('/user:\d+/', 'user:***', $e->key)
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: fortify-development
|
name: fortify-development
|
||||||
description: 'ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.'
|
description: 'ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), passkeys, profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, passkeys, WebAuthn, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.'
|
||||||
license: MIT
|
license: MIT
|
||||||
metadata:
|
metadata:
|
||||||
author: laravel
|
author: laravel
|
||||||
|
|
@ -32,6 +32,7 @@ ## Available Features
|
||||||
- `Features::updateProfileInformation()` - Profile updates
|
- `Features::updateProfileInformation()` - Profile updates
|
||||||
- `Features::updatePasswords()` - Password changes
|
- `Features::updatePasswords()` - Password changes
|
||||||
- `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes
|
- `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes
|
||||||
|
- `Features::passkeys()` - Passwordless authentication with WebAuthn passkeys
|
||||||
|
|
||||||
> Use `search-docs` for feature configuration options and customization patterns.
|
> Use `search-docs` for feature configuration options and customization patterns.
|
||||||
|
|
||||||
|
|
@ -50,6 +51,18 @@ ### Two-Factor Authentication Setup
|
||||||
|
|
||||||
> Use `search-docs` for TOTP implementation and recovery code handling patterns.
|
> Use `search-docs` for TOTP implementation and recovery code handling patterns.
|
||||||
|
|
||||||
|
### Passkeys Setup
|
||||||
|
|
||||||
|
```
|
||||||
|
- [ ] Add PasskeyAuthenticatable trait to User model and implement PasskeyUser
|
||||||
|
- [ ] Enable passkeys feature in config/fortify.php
|
||||||
|
- [ ] If the passkeys table migration is missing, publish via `php artisan vendor:publish --tag=fortify-migrations` and migrate
|
||||||
|
- [ ] Configure passkeys relying_party_id, allowed_origins, user_handle_secret, and timeout if defaults are not suitable
|
||||||
|
- [ ] Build UI with @laravel/passkeys for registration, login, confirmation, and deletion
|
||||||
|
```
|
||||||
|
|
||||||
|
> Use `search-docs` for passkey configuration options. For `@laravel/passkeys` frontend usage, refer to the package's README on npm.
|
||||||
|
|
||||||
### Email Verification Setup
|
### Email Verification Setup
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -129,3 +142,10 @@ ## Key Endpoints
|
||||||
| 2FA Challenge | POST | `/two-factor-challenge` |
|
| 2FA Challenge | POST | `/two-factor-challenge` |
|
||||||
| Get QR Code | GET | `/user/two-factor-qr-code` |
|
| Get QR Code | GET | `/user/two-factor-qr-code` |
|
||||||
| Recovery Codes | GET/POST | `/user/two-factor-recovery-codes` |
|
| Recovery Codes | GET/POST | `/user/two-factor-recovery-codes` |
|
||||||
|
| Passkey Login Options | GET | `/passkeys/login/options` |
|
||||||
|
| Passkey Login | POST | `/passkeys/login` |
|
||||||
|
| Passkey Confirm Options| GET | `/passkeys/confirm/options` |
|
||||||
|
| Passkey Confirm | POST | `/passkeys/confirm` |
|
||||||
|
| Passkey Options | GET | `/user/passkeys/options` |
|
||||||
|
| Register Passkey | POST | `/user/passkeys` |
|
||||||
|
| Delete Passkey | DELETE | `/user/passkeys/{passkey}` |
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ ### 8. Testing Patterns → `rules/testing.md`
|
||||||
### 9. Queue & Job Patterns → `rules/queue-jobs.md`
|
### 9. Queue & Job Patterns → `rules/queue-jobs.md`
|
||||||
|
|
||||||
- `retry_after` must exceed job `timeout`; use exponential backoff `[1, 5, 10]`
|
- `retry_after` must exceed job `timeout`; use exponential backoff `[1, 5, 10]`
|
||||||
- `ShouldBeUnique` to prevent duplicates; `WithoutOverlapping::untilProcessing()` for concurrency
|
- `ShouldBeUnique` to prevent duplicates; `ShouldBeUniqueUntilProcessing` for early lock release
|
||||||
- Always implement `failed()`; with `retryUntil()`, set `$tries = 0`
|
- Always implement `failed()`; with `retryUntil()`, set `$tries = 0`
|
||||||
- `RateLimited` middleware for external API calls; `Bus::batch()` for related jobs
|
- `RateLimited` middleware for external API calls; `Bus::batch()` for related jobs
|
||||||
- Horizon for complex multi-queue scenarios
|
- Horizon for complex multi-queue scenarios
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ ## Code to Interfaces
|
||||||
|
|
||||||
## Default Sort by Descending
|
## Default Sort by Descending
|
||||||
|
|
||||||
When no explicit order is specified, sort by `id` or `created_at` descending. Explicit ordering prevents cross-database inconsistencies between MySQL and Postgres.
|
When no explicit order is specified, sort by `id` or `created_at` descending. Without an explicit `ORDER BY`, row order is undefined.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ # Caching Best Practices
|
||||||
|
|
||||||
## Use `Cache::remember()` Instead of Manual Get/Put
|
## Use `Cache::remember()` Instead of Manual Get/Put
|
||||||
|
|
||||||
Atomic pattern prevents race conditions and removes boilerplate.
|
Cleaner cache-aside pattern that removes boilerplate. use `Cache::lock()` for race conditions.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ # Configuration Best Practices
|
||||||
|
|
||||||
## `env()` Only in Config Files
|
## `env()` Only in Config Files
|
||||||
|
|
||||||
Direct `env()` calls return `null` when config is cached.
|
Direct `env()` calls may return `null` when config is cached.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,11 @@ ## Always Queue Notifications
|
||||||
|
|
||||||
## Use `afterCommit()` on Notifications in Transactions
|
## Use `afterCommit()` on Notifications in Transactions
|
||||||
|
|
||||||
Same race condition as events — the queued notification job may run before the transaction commits.
|
Same race condition as events — call `afterCommit()` to delay dispatch until the transaction commits.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$user->notify((new InvoicePaid($invoice))->afterCommit());
|
||||||
|
```
|
||||||
|
|
||||||
## Route Notification Channels to Dedicated Queues
|
## Route Notification Channels to Dedicated Queues
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ ## Use Retry with Backoff for External APIs
|
||||||
Only retry on specific errors:
|
Only retry on specific errors:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$response = Http::retry(3, 100, function (Exception $exception, PendingRequest $request) {
|
$response = Http::retry(3, 100, function (Throwable $exception, PendingRequest $request) {
|
||||||
return $exception instanceof ConnectionException
|
return $exception instanceof ConnectionException
|
||||||
|| ($exception instanceof RequestException && $exception->response->serverError());
|
|| ($exception instanceof RequestException && $exception->response->serverError());
|
||||||
})->post('https://api.example.com/data');
|
})->post('https://api.example.com/data');
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ ## Use `afterCommit()` on Mailables Inside Transactions
|
||||||
|
|
||||||
## Use `assertQueued()` Not `assertSent()` for Queued Mailables
|
## Use `assertQueued()` Not `assertSent()` for Queued Mailables
|
||||||
|
|
||||||
`Mail::assertSent()` only catches synchronous mail. Queued mailables silently pass `assertSent`, giving false confidence.
|
`Mail::assertSent()` only catches synchronous mail. Queued mailables fail `assertSent` with a "Did you mean to use assertQueued()?" hint.
|
||||||
|
|
||||||
Incorrect: `Mail::assertSent(OrderShipped::class);` when mailable implements `ShouldQueue`.
|
Incorrect: `Mail::assertSent(OrderShipped::class);` when mailable implements `ShouldQueue`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,25 +106,23 @@ ## `retryUntil()` Needs `$tries = 0`
|
||||||
```php
|
```php
|
||||||
public $tries = 0;
|
public $tries = 0;
|
||||||
|
|
||||||
public function retryUntil(): DateTime
|
public function retryUntil(): \DateTimeInterface
|
||||||
{
|
{
|
||||||
return now()->addHours(4);
|
return now()->addHours(4);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use `WithoutOverlapping::untilProcessing()`
|
## Use `ShouldBeUniqueUntilProcessing` for Early Lock Release
|
||||||
|
|
||||||
Prevents concurrent execution while allowing new instances to queue.
|
`ShouldBeUnique` holds the lock until the job completes. `ShouldBeUniqueUntilProcessing` releases it when processing starts, allowing new instances to queue.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function middleware(): array
|
class UpdateSearchIndex implements ShouldQueue, ShouldBeUniqueUntilProcessing
|
||||||
{
|
{
|
||||||
return [new WithoutOverlapping($this->product->id)->untilProcessing()];
|
// Lock releases when processing begins, not when it finishes
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Without `untilProcessing()`, the lock extends through queue wait time. With it, the lock releases when processing starts.
|
|
||||||
|
|
||||||
## Use Horizon for Complex Queue Scenarios
|
## Use Horizon for Complex Queue Scenarios
|
||||||
|
|
||||||
Use Laravel Horizon when you need monitoring, auto-scaling, failure tracking, or multiple queues with different priorities.
|
Use Laravel Horizon when you need monitoring, auto-scaling, failure tracking, or multiple queues with different priorities.
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ ## Use Resource Controllers
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Route::resource('posts', PostController::class);
|
Route::resource('posts', PostController::class);
|
||||||
Route::apiResource('api/posts', Api\PostController::class);
|
// In routes/api.php — the /api prefix is applied automatically
|
||||||
|
Route::apiResource('posts', Api\PostController::class);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Keep Controllers Thin
|
## Keep Controllers Thin
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ ## Authorize Every Action
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```php
|
```php
|
||||||
public function update(Request $request, Post $post)
|
public function update(UpdatePostRequest $request, Post $post)
|
||||||
{
|
{
|
||||||
$post->update($request->validated());
|
$post->update($request->validated());
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ ## Escape Output to Prevent XSS
|
||||||
|
|
||||||
## CSRF Protection
|
## CSRF Protection
|
||||||
|
|
||||||
Include `@csrf` in all POST/PUT/DELETE Blade forms. Not needed in Inertia.
|
Include `@csrf` in all POST/PUT/DELETE Blade forms. In Inertia apps, the `@csrf` directive is automatically applied.
|
||||||
|
|
||||||
Incorrect:
|
Incorrect:
|
||||||
```blade
|
```blade
|
||||||
|
|
@ -121,7 +121,7 @@ ## Rate Limit Auth and API Routes
|
||||||
|
|
||||||
## Validate File Uploads
|
## Validate File Uploads
|
||||||
|
|
||||||
Validate MIME type, extension, and size. Never trust client-provided filenames.
|
Validate extension, MIME type, and size. The `mimes` rule checks extensions; use `mimetypes` for actual MIME type validation. Never trust client-provided filenames.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -2,7 +2,7 @@ # Testing Best Practices
|
||||||
|
|
||||||
## Use `LazilyRefreshDatabase` Over `RefreshDatabase`
|
## Use `LazilyRefreshDatabase` Over `RefreshDatabase`
|
||||||
|
|
||||||
`RefreshDatabase` runs all migrations every test run even when the schema hasn't changed. `LazilyRefreshDatabase` only migrates when needed, significantly speeding up large suites.
|
`RefreshDatabase` migrates once per process and wraps each test in a rolled-back transaction. `LazilyRefreshDatabase` skips even that first migration if the schema is already up to date.
|
||||||
|
|
||||||
## Use Model Assertions Over Raw Database Assertions
|
## Use Model Assertions Over Raw Database Assertions
|
||||||
|
|
||||||
|
|
|
||||||
96
.cursor/skills/mcp-development/SKILL.md
Normal file
96
.cursor/skills/mcp-development/SKILL.md
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
---
|
||||||
|
name: mcp-development
|
||||||
|
description: "Use this skill for Laravel MCP development only. Trigger when creating or editing MCP tools, resources, prompts, or servers in Laravel projects. Covers: artisan make:mcp-* generators, mcp:inspector, routes/ai.php, Tool/Resource/Prompt classes, schema validation, shouldRegister(), OAuth setup, URI templates, read-only attributes, and MCP debugging. Do not use for non-Laravel MCP projects or generic AI features without MCP."
|
||||||
|
license: MIT
|
||||||
|
metadata:
|
||||||
|
author: laravel
|
||||||
|
---
|
||||||
|
|
||||||
|
# MCP Development
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Use `search-docs` for detailed Laravel MCP patterns and documentation.
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
Register MCP servers in `routes/ai.php`:
|
||||||
|
|
||||||
|
<!-- Register MCP Server -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Facades\Mcp;
|
||||||
|
|
||||||
|
Mcp::web();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating MCP Primitives
|
||||||
|
|
||||||
|
Create MCP tools, resources, prompts, and servers using artisan commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan make:mcp-tool ToolName # Create a tool
|
||||||
|
|
||||||
|
php artisan make:mcp-resource ResourceName # Create a resource
|
||||||
|
|
||||||
|
php artisan make:mcp-prompt PromptName # Create a prompt
|
||||||
|
|
||||||
|
php artisan make:mcp-server ServerName # Create a server
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
After creating primitives, register them in your server's `$tools`, `$resources`, or `$prompts` properties.
|
||||||
|
|
||||||
|
### Tools
|
||||||
|
|
||||||
|
<!-- MCP Tool Example -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Server\Tool;
|
||||||
|
use Laravel\Mcp\Server\Request;
|
||||||
|
use Laravel\Mcp\Server\Response;
|
||||||
|
|
||||||
|
class MyTool extends Tool
|
||||||
|
{
|
||||||
|
public function handle(Request $request): Response
|
||||||
|
{
|
||||||
|
return new Response(['result' => 'success']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Registering Primitives in a Server
|
||||||
|
|
||||||
|
Each MCP server must explicitly declare the tools, resources, and prompts it exposes.
|
||||||
|
|
||||||
|
<!-- Register Primitives in MCP Server -->
|
||||||
|
```php
|
||||||
|
use Laravel\Mcp\Server;
|
||||||
|
|
||||||
|
class AppServer extends Server
|
||||||
|
{
|
||||||
|
protected array $tools = [
|
||||||
|
\App\Mcp\Tools\MyTool::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected array $resources = [
|
||||||
|
\App\Mcp\Resources\MyResource::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected array $prompts = [
|
||||||
|
\App\Mcp\Prompts\MyPrompt::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
1. Check `routes/ai.php` for proper registration
|
||||||
|
2. Test tool via MCP client
|
||||||
|
|
||||||
|
## Common Pitfalls
|
||||||
|
|
||||||
|
- Running `mcp:start` command (it hangs waiting for input)
|
||||||
|
- Using HTTPS locally with Node-based MCP clients
|
||||||
|
- Not using `search-docs` for the latest MCP documentation
|
||||||
|
- Not registering MCP server routes in `routes/ai.php`
|
||||||
|
- Do not register `ai.php` in `bootstrap.php`; it is registered automatically.
|
||||||
|
- OAuth registration supports custom URI schemes (e.g., `cursor://`, `vscode://`) for native desktop clients via `mcp.custom_schemes` config
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: pest-testing
|
name: pest-testing
|
||||||
description: "Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code."
|
description: "Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: test()/it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code."
|
||||||
license: MIT
|
license: MIT
|
||||||
metadata:
|
metadata:
|
||||||
author: laravel
|
author: laravel
|
||||||
|
|
@ -18,6 +18,12 @@ ### Creating Tests
|
||||||
|
|
||||||
All tests must be written using Pest. Use `php artisan make:test --pest {name}`.
|
All tests must be written using Pest. Use `php artisan make:test --pest {name}`.
|
||||||
|
|
||||||
|
The `{name}` argument should include only the path and test name, but should not include the test suite.
|
||||||
|
- Incorrect: `php artisan make:test --pest Feature/SomeFeatureTest` will generate `tests/Feature/Feature/SomeFeatureTest.php`
|
||||||
|
- Correct: `php artisan make:test --pest SomeControllerTest` will generate `tests/Feature/SomeControllerTest.php`
|
||||||
|
- Incorrect: `php artisan make:test --pest --unit Unit/SomeServiceTest` will generate `tests/Unit/Unit/SomeServiceTest.php`
|
||||||
|
- Correct: `php artisan make:test --pest --unit SomeServiceTest` will generate `tests/Unit/SomeServiceTest.php`
|
||||||
|
|
||||||
### Test Organization
|
### Test Organization
|
||||||
|
|
||||||
- Unit/Feature tests: `tests/Feature` and `tests/Unit` directories.
|
- Unit/Feature tests: `tests/Feature` and `tests/Unit` directories.
|
||||||
|
|
@ -26,6 +32,8 @@ ### Test Organization
|
||||||
|
|
||||||
### Basic Test Structure
|
### Basic Test Structure
|
||||||
|
|
||||||
|
Pest supports both `test()` and `it()` functions. Before writing new tests, check existing test files in the same directory to match the project's convention. Use `test()` if existing tests use `test()`, or `it()` if they use `it()`.
|
||||||
|
|
||||||
<!-- Basic Pest Test Example -->
|
<!-- Basic Pest Test Example -->
|
||||||
```php
|
```php
|
||||||
it('is true', function () {
|
it('is true', function () {
|
||||||
|
|
@ -155,3 +163,4 @@ ## Common Pitfalls
|
||||||
- Forgetting datasets for repetitive validation tests
|
- Forgetting datasets for repetitive validation tests
|
||||||
- Deleting tests without approval
|
- Deleting tests without approval
|
||||||
- Forgetting `assertNoJavaScriptErrors()` in browser tests
|
- Forgetting `assertNoJavaScriptErrors()` in browser tests
|
||||||
|
- Prefixing `Feature/` or `Unit/` in `{name}` when using `make:test`
|
||||||
|
|
|
||||||
26
AGENTS.md
26
AGENTS.md
|
|
@ -17,6 +17,7 @@ ## Foundational Context
|
||||||
- laravel/fortify (FORTIFY) - v1
|
- laravel/fortify (FORTIFY) - v1
|
||||||
- laravel/framework (LARAVEL) - v12
|
- laravel/framework (LARAVEL) - v12
|
||||||
- laravel/horizon (HORIZON) - v5
|
- laravel/horizon (HORIZON) - v5
|
||||||
|
- laravel/mcp (MCP) - v0
|
||||||
- laravel/nightwatch (NIGHTWATCH) - v1
|
- laravel/nightwatch (NIGHTWATCH) - v1
|
||||||
- laravel/pail (PAIL) - v1
|
- laravel/pail (PAIL) - v1
|
||||||
- laravel/prompts (PROMPTS) - v0
|
- laravel/prompts (PROMPTS) - v0
|
||||||
|
|
@ -25,29 +26,16 @@ ## Foundational Context
|
||||||
- livewire/livewire (LIVEWIRE) - v3
|
- livewire/livewire (LIVEWIRE) - v3
|
||||||
- laravel/boost (BOOST) - v2
|
- laravel/boost (BOOST) - v2
|
||||||
- laravel/dusk (DUSK) - v8
|
- laravel/dusk (DUSK) - v8
|
||||||
- laravel/mcp (MCP) - v0
|
|
||||||
- laravel/pint (PINT) - v1
|
- laravel/pint (PINT) - v1
|
||||||
- laravel/telescope (TELESCOPE) - v5
|
- laravel/telescope (TELESCOPE) - v5
|
||||||
- pestphp/pest (PEST) - v4
|
- pestphp/pest (PEST) - v4
|
||||||
- phpunit/phpunit (PHPUNIT) - v12
|
- phpunit/phpunit (PHPUNIT) - v12
|
||||||
- rector/rector (RECTOR) - v2
|
- rector/rector (RECTOR) - v2
|
||||||
- laravel-echo (ECHO) - v2
|
|
||||||
- tailwindcss (TAILWINDCSS) - v4
|
- tailwindcss (TAILWINDCSS) - v4
|
||||||
- vue (VUE) - v3
|
|
||||||
|
|
||||||
## Skills Activation
|
## Skills Activation
|
||||||
|
|
||||||
This project has domain-specific skills available. You MUST activate the relevant skill whenever you work in that domain—don't wait until you're stuck.
|
This project has domain-specific skills available in `**/skills/**`. You MUST activate the relevant skill whenever you work in that domain—don't wait until you're stuck.
|
||||||
|
|
||||||
- `laravel-best-practices` — Apply this skill whenever writing, reviewing, or refactoring Laravel PHP code. This includes creating or modifying controllers, models, migrations, form requests, policies, jobs, scheduled commands, service classes, and Eloquent queries. Triggers for N+1 and query performance issues, caching strategies, authorization and security patterns, validation, error handling, queue and job configuration, route definitions, and architectural decisions. Also use for Laravel code reviews and refactoring existing Laravel code to follow best practices. Covers any task involving Laravel backend PHP code patterns.
|
|
||||||
- `configuring-horizon` — Use this skill whenever the user mentions Horizon by name in a Laravel context. Covers the full Horizon lifecycle: installing Horizon (horizon:install, Sail setup), configuring config/horizon.php (supervisor blocks, queue assignments, balancing strategies, minProcesses/maxProcesses), fixing the dashboard (authorization via Gate::define viewHorizon, blank metrics, horizon:snapshot scheduling), and troubleshooting production issues (worker crashes, timeout chain ordering, LongWaitDetected notifications, waits config). Also covers job tagging and silencing. Do not use for generic Laravel queues without Horizon, SQS or database drivers, standalone Redis setup, Linux supervisord, Telescope, or job batching.
|
|
||||||
- `socialite-development` — Manages OAuth social authentication with Laravel Socialite. Activate when adding social login providers; configuring OAuth redirect/callback flows; retrieving authenticated user details; customizing scopes or parameters; setting up community providers; testing with Socialite fakes; or when the user mentions social login, OAuth, Socialite, or third-party authentication.
|
|
||||||
- `livewire-development` — Use for any task or question involving Livewire. Activate if user mentions Livewire, wire: directives, or Livewire-specific concepts like wire:model, wire:click, invoke this skill. Covers building new components, debugging reactivity issues, real-time form validation, loading states, migrating from Livewire 2 to 3, converting component formats (SFC/MFC/class-based), and performance optimization. Do not use for non-Livewire reactive UI (React, Vue, Alpine-only, Inertia.js) or standard Laravel forms without Livewire.
|
|
||||||
- `pest-testing` — Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code.
|
|
||||||
- `tailwindcss-development` — Always invoke when the user's message includes 'tailwind' in any form. Also invoke for: building responsive grid layouts (multi-column card grids, product grids), flex/grid page structures (dashboards with sidebars, fixed topbars, mobile-toggle navs), styling UI components (cards, tables, navbars, pricing sections, forms, inputs, badges), adding dark mode variants, fixing spacing or typography, and Tailwind v3/v4 work. The core use case: writing or fixing Tailwind utility classes in HTML templates (Blade, JSX, Vue). Skip for backend PHP logic, database queries, API routes, JavaScript with no HTML/CSS component, CSS file audits, build tool configuration, and vanilla CSS.
|
|
||||||
- `fortify-development` — ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.
|
|
||||||
- `laravel-actions` — Build, refactor, and troubleshoot Laravel Actions using lorisleiva/laravel-actions. Use when implementing reusable action classes (object/controller/job/listener/command), converting service classes/controllers/jobs into actions, orchestrating workflows via faked actions, or debugging action entrypoints and wiring.
|
|
||||||
- `debugging-output-and-previewing-html-using-ray` — Use when user says "send to Ray," "show in Ray," "debug in Ray," "log to Ray," "display in Ray," or wants to visualize data, debug output, or show diagrams in the Ray desktop application.
|
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
|
|
@ -107,7 +95,6 @@ ## Artisan
|
||||||
- Run Artisan commands directly via the command line (e.g., `php artisan route:list`). Use `php artisan list` to discover available commands and `php artisan [command] --help` to check parameters.
|
- Run Artisan commands directly via the command line (e.g., `php artisan route:list`). Use `php artisan list` to discover available commands and `php artisan [command] --help` to check parameters.
|
||||||
- Inspect routes with `php artisan route:list`. Filter with: `--method=GET`, `--name=users`, `--path=api`, `--except-vendor`, `--only-vendor`.
|
- Inspect routes with `php artisan route:list`. Filter with: `--method=GET`, `--name=users`, `--path=api`, `--except-vendor`, `--only-vendor`.
|
||||||
- Read configuration values using dot notation: `php artisan config:show app.name`, `php artisan config:show database.default`. Or read config files directly from the `config/` directory.
|
- Read configuration values using dot notation: `php artisan config:show app.name`, `php artisan config:show database.default`. Or read config files directly from the `config/` directory.
|
||||||
- To check environment variables, read the `.env` file directly.
|
|
||||||
|
|
||||||
## Tinker
|
## Tinker
|
||||||
|
|
||||||
|
|
@ -122,10 +109,16 @@ # PHP
|
||||||
- Always use curly braces for control structures, even for single-line bodies.
|
- Always use curly braces for control structures, even for single-line bodies.
|
||||||
- Use PHP 8 constructor property promotion: `public function __construct(public GitHub $github) { }`. Do not leave empty zero-parameter `__construct()` methods unless the constructor is private.
|
- Use PHP 8 constructor property promotion: `public function __construct(public GitHub $github) { }`. Do not leave empty zero-parameter `__construct()` methods unless the constructor is private.
|
||||||
- Use explicit return type declarations and type hints for all method parameters: `function isAccessible(User $user, ?string $path = null): bool`
|
- Use explicit return type declarations and type hints for all method parameters: `function isAccessible(User $user, ?string $path = null): bool`
|
||||||
- Use TitleCase for Enum keys: `FavoritePerson`, `BestLake`, `Monthly`.
|
- Follow existing application Enum naming conventions.
|
||||||
- Prefer PHPDoc blocks over inline comments. Only add inline comments for exceptionally complex logic.
|
- Prefer PHPDoc blocks over inline comments. Only add inline comments for exceptionally complex logic.
|
||||||
- Use array shape type definitions in PHPDoc blocks.
|
- Use array shape type definitions in PHPDoc blocks.
|
||||||
|
|
||||||
|
=== deployments rules ===
|
||||||
|
|
||||||
|
# Deployment
|
||||||
|
|
||||||
|
- Laravel can be deployed using [Laravel Cloud](https://cloud.laravel.com/), which is the fastest way to deploy and scale production Laravel applications.
|
||||||
|
|
||||||
=== tests rules ===
|
=== tests rules ===
|
||||||
|
|
||||||
# Test Enforcement
|
# Test Enforcement
|
||||||
|
|
@ -209,6 +202,7 @@ # Laravel Pint Code Formatter
|
||||||
## Pest
|
## Pest
|
||||||
|
|
||||||
- This project uses Pest for testing. Create tests: `php artisan make:test --pest {name}`.
|
- This project uses Pest for testing. Create tests: `php artisan make:test --pest {name}`.
|
||||||
|
- The `{name}` argument should not include the test suite directory. Use `php artisan make:test --pest SomeFeatureTest` instead of `php artisan make:test --pest Feature/SomeFeatureTest`.
|
||||||
- Run tests: `php artisan test --compact` or filter: `php artisan test --compact --filter=testName`.
|
- Run tests: `php artisan test --compact` or filter: `php artisan test --compact --filter=testName`.
|
||||||
- Do NOT delete tests without approval.
|
- Do NOT delete tests without approval.
|
||||||
|
|
||||||
|
|
|
||||||
26
CLAUDE.md
26
CLAUDE.md
|
|
@ -120,6 +120,7 @@ ## Foundational Context
|
||||||
- laravel/fortify (FORTIFY) - v1
|
- laravel/fortify (FORTIFY) - v1
|
||||||
- laravel/framework (LARAVEL) - v12
|
- laravel/framework (LARAVEL) - v12
|
||||||
- laravel/horizon (HORIZON) - v5
|
- laravel/horizon (HORIZON) - v5
|
||||||
|
- laravel/mcp (MCP) - v0
|
||||||
- laravel/nightwatch (NIGHTWATCH) - v1
|
- laravel/nightwatch (NIGHTWATCH) - v1
|
||||||
- laravel/pail (PAIL) - v1
|
- laravel/pail (PAIL) - v1
|
||||||
- laravel/prompts (PROMPTS) - v0
|
- laravel/prompts (PROMPTS) - v0
|
||||||
|
|
@ -128,29 +129,16 @@ ## Foundational Context
|
||||||
- livewire/livewire (LIVEWIRE) - v3
|
- livewire/livewire (LIVEWIRE) - v3
|
||||||
- laravel/boost (BOOST) - v2
|
- laravel/boost (BOOST) - v2
|
||||||
- laravel/dusk (DUSK) - v8
|
- laravel/dusk (DUSK) - v8
|
||||||
- laravel/mcp (MCP) - v0
|
|
||||||
- laravel/pint (PINT) - v1
|
- laravel/pint (PINT) - v1
|
||||||
- laravel/telescope (TELESCOPE) - v5
|
- laravel/telescope (TELESCOPE) - v5
|
||||||
- pestphp/pest (PEST) - v4
|
- pestphp/pest (PEST) - v4
|
||||||
- phpunit/phpunit (PHPUNIT) - v12
|
- phpunit/phpunit (PHPUNIT) - v12
|
||||||
- rector/rector (RECTOR) - v2
|
- rector/rector (RECTOR) - v2
|
||||||
- laravel-echo (ECHO) - v2
|
|
||||||
- tailwindcss (TAILWINDCSS) - v4
|
- tailwindcss (TAILWINDCSS) - v4
|
||||||
- vue (VUE) - v3
|
|
||||||
|
|
||||||
## Skills Activation
|
## Skills Activation
|
||||||
|
|
||||||
This project has domain-specific skills available. You MUST activate the relevant skill whenever you work in that domain—don't wait until you're stuck.
|
This project has domain-specific skills available in `**/skills/**`. You MUST activate the relevant skill whenever you work in that domain—don't wait until you're stuck.
|
||||||
|
|
||||||
- `laravel-best-practices` — Apply this skill whenever writing, reviewing, or refactoring Laravel PHP code. This includes creating or modifying controllers, models, migrations, form requests, policies, jobs, scheduled commands, service classes, and Eloquent queries. Triggers for N+1 and query performance issues, caching strategies, authorization and security patterns, validation, error handling, queue and job configuration, route definitions, and architectural decisions. Also use for Laravel code reviews and refactoring existing Laravel code to follow best practices. Covers any task involving Laravel backend PHP code patterns.
|
|
||||||
- `configuring-horizon` — Use this skill whenever the user mentions Horizon by name in a Laravel context. Covers the full Horizon lifecycle: installing Horizon (horizon:install, Sail setup), configuring config/horizon.php (supervisor blocks, queue assignments, balancing strategies, minProcesses/maxProcesses), fixing the dashboard (authorization via Gate::define viewHorizon, blank metrics, horizon:snapshot scheduling), and troubleshooting production issues (worker crashes, timeout chain ordering, LongWaitDetected notifications, waits config). Also covers job tagging and silencing. Do not use for generic Laravel queues without Horizon, SQS or database drivers, standalone Redis setup, Linux supervisord, Telescope, or job batching.
|
|
||||||
- `socialite-development` — Manages OAuth social authentication with Laravel Socialite. Activate when adding social login providers; configuring OAuth redirect/callback flows; retrieving authenticated user details; customizing scopes or parameters; setting up community providers; testing with Socialite fakes; or when the user mentions social login, OAuth, Socialite, or third-party authentication.
|
|
||||||
- `livewire-development` — Use for any task or question involving Livewire. Activate if user mentions Livewire, wire: directives, or Livewire-specific concepts like wire:model, wire:click, invoke this skill. Covers building new components, debugging reactivity issues, real-time form validation, loading states, migrating from Livewire 2 to 3, converting component formats (SFC/MFC/class-based), and performance optimization. Do not use for non-Livewire reactive UI (React, Vue, Alpine-only, Inertia.js) or standard Laravel forms without Livewire.
|
|
||||||
- `pest-testing` — Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code.
|
|
||||||
- `tailwindcss-development` — Always invoke when the user's message includes 'tailwind' in any form. Also invoke for: building responsive grid layouts (multi-column card grids, product grids), flex/grid page structures (dashboards with sidebars, fixed topbars, mobile-toggle navs), styling UI components (cards, tables, navbars, pricing sections, forms, inputs, badges), adding dark mode variants, fixing spacing or typography, and Tailwind v3/v4 work. The core use case: writing or fixing Tailwind utility classes in HTML templates (Blade, JSX, Vue). Skip for backend PHP logic, database queries, API routes, JavaScript with no HTML/CSS component, CSS file audits, build tool configuration, and vanilla CSS.
|
|
||||||
- `fortify-development` — ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.
|
|
||||||
- `laravel-actions` — Build, refactor, and troubleshoot Laravel Actions using lorisleiva/laravel-actions. Use when implementing reusable action classes (object/controller/job/listener/command), converting service classes/controllers/jobs into actions, orchestrating workflows via faked actions, or debugging action entrypoints and wiring.
|
|
||||||
- `debugging-output-and-previewing-html-using-ray` — Use when user says "send to Ray," "show in Ray," "debug in Ray," "log to Ray," "display in Ray," or wants to visualize data, debug output, or show diagrams in the Ray desktop application.
|
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
|
|
@ -210,7 +198,6 @@ ## Artisan
|
||||||
- Run Artisan commands directly via the command line (e.g., `php artisan route:list`). Use `php artisan list` to discover available commands and `php artisan [command] --help` to check parameters.
|
- Run Artisan commands directly via the command line (e.g., `php artisan route:list`). Use `php artisan list` to discover available commands and `php artisan [command] --help` to check parameters.
|
||||||
- Inspect routes with `php artisan route:list`. Filter with: `--method=GET`, `--name=users`, `--path=api`, `--except-vendor`, `--only-vendor`.
|
- Inspect routes with `php artisan route:list`. Filter with: `--method=GET`, `--name=users`, `--path=api`, `--except-vendor`, `--only-vendor`.
|
||||||
- Read configuration values using dot notation: `php artisan config:show app.name`, `php artisan config:show database.default`. Or read config files directly from the `config/` directory.
|
- Read configuration values using dot notation: `php artisan config:show app.name`, `php artisan config:show database.default`. Or read config files directly from the `config/` directory.
|
||||||
- To check environment variables, read the `.env` file directly.
|
|
||||||
|
|
||||||
## Tinker
|
## Tinker
|
||||||
|
|
||||||
|
|
@ -225,10 +212,16 @@ # PHP
|
||||||
- Always use curly braces for control structures, even for single-line bodies.
|
- Always use curly braces for control structures, even for single-line bodies.
|
||||||
- Use PHP 8 constructor property promotion: `public function __construct(public GitHub $github) { }`. Do not leave empty zero-parameter `__construct()` methods unless the constructor is private.
|
- Use PHP 8 constructor property promotion: `public function __construct(public GitHub $github) { }`. Do not leave empty zero-parameter `__construct()` methods unless the constructor is private.
|
||||||
- Use explicit return type declarations and type hints for all method parameters: `function isAccessible(User $user, ?string $path = null): bool`
|
- Use explicit return type declarations and type hints for all method parameters: `function isAccessible(User $user, ?string $path = null): bool`
|
||||||
- Use TitleCase for Enum keys: `FavoritePerson`, `BestLake`, `Monthly`.
|
- Follow existing application Enum naming conventions.
|
||||||
- Prefer PHPDoc blocks over inline comments. Only add inline comments for exceptionally complex logic.
|
- Prefer PHPDoc blocks over inline comments. Only add inline comments for exceptionally complex logic.
|
||||||
- Use array shape type definitions in PHPDoc blocks.
|
- Use array shape type definitions in PHPDoc blocks.
|
||||||
|
|
||||||
|
=== deployments rules ===
|
||||||
|
|
||||||
|
# Deployment
|
||||||
|
|
||||||
|
- Laravel can be deployed using [Laravel Cloud](https://cloud.laravel.com/), which is the fastest way to deploy and scale production Laravel applications.
|
||||||
|
|
||||||
=== tests rules ===
|
=== tests rules ===
|
||||||
|
|
||||||
# Test Enforcement
|
# Test Enforcement
|
||||||
|
|
@ -312,6 +305,7 @@ # Laravel Pint Code Formatter
|
||||||
## Pest
|
## Pest
|
||||||
|
|
||||||
- This project uses Pest for testing. Create tests: `php artisan make:test --pest {name}`.
|
- This project uses Pest for testing. Create tests: `php artisan make:test --pest {name}`.
|
||||||
|
- The `{name}` argument should not include the test suite directory. Use `php artisan make:test --pest SomeFeatureTest` instead of `php artisan make:test --pest Feature/SomeFeatureTest`.
|
||||||
- Run tests: `php artisan test --compact` or filter: `php artisan test --compact --filter=testName`.
|
- Run tests: `php artisan test --compact` or filter: `php artisan test --compact --filter=testName`.
|
||||||
- Do NOT delete tests without approval.
|
- Do NOT delete tests without approval.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue