Impact Sentinel
A skill focused on impact analysis, breaking change detection, strategic database design, and comprehensive database indexing review.
Purpose
The ask-impact-sentinel skill guides AI agents to think critically about the consequences of their changes. It ensures that optimizations don't break existing functionality and that database interactions are designed for performance and reliability.
Usage
Apply this skill when:
- Modifying core functions or shared utilities.
- Refactoring existing logic that has many dependencies.
- Designing or optimizing database schemas and queries.
- Adding, modifying, or reviewing any feature that involves database reads or writes.
- Preparing for a release where stability is paramount.
Core Protocol
- Impact Analysis: Identify downstream effects of every code change.
- Regression Prevention: Validate that existing features remain functional.
- Automated Validation: Before clearing any code for production, you must explicitly run backend checks:
- Syntax & Core Framework Validation: Run strict framework linting using the CLI (e.g.
php -l path/to/file.php or npm run lint).
- Web Routing & Status Code Validation: Spin up terminal clients to internally ping root routes directly from the framework engine to confirm HTTP 200 statuses and ensure global middlewares didn't crash the stack (e.g. for Laravel:
php artisan tinker --execute="echo app()->handle(Illuminate\Http\Request::create('/', 'GET'))->getStatusCode();").
- Intelligent Optimization: Focus on high-impact areas without introducing side effects.
- Strategic Data Access: Prioritize efficient query design and database best practices.
- Database Indexing Review: For every module and controller touched, execute a comprehensive indexing analysis (see dedicated section below).
Examples
Before Impact Analysis
# Modifying a shared utility without checking dependents
def get_user_data(user_id):
return db.query("SELECT * FROM users WHERE id = ?", user_id)
After Impact Analysis
# Checking dependents and ensuring no breaking changes
def get_user_data(user_id):
# Verified that 5 other modules use this.
# Adding a cache layer instead of changing the return structure.
data = redis.get(f"user:{user_id}")
if not data:
data = db.query("SELECT * FROM users WHERE id = ?", user_id)
redis.set(f"user:{user_id}", data)
return data
Database Indexing Review Protocol
For every module and controller the sentinel works on, a comprehensive database indexing review is mandatory. This analysis must extend beyond the modified file to cover all related models, services, repositories, and database tables involved in the request.
Scope of Analysis
When triggered, the indexing review must cover:
- The modified controller or module itself.
- All Eloquent/ORM models referenced directly or indirectly.
- Service classes and repository layers that execute queries on behalf of the controller.
- Database tables involved in joins, subqueries, and relationship eager-loads.
- Scheduled jobs, observers, or event listeners that query the same tables.
Step-by-Step Procedure
Query Discovery
- Trace every database query executed by the feature (including relationships, scopes, and raw queries).
- List each query with its origin (model, service, repository, or raw statement).
- Flag N+1 patterns, full-table scans, and unoptimized joins.
Existing Index Audit
- Retrieve the current index definitions for every involved table.
- For SQL databases, run or simulate
SHOW INDEX FROM <table> (MySQL) or \d <table> (PostgreSQL).
- For MongoDB, inspect
db.collection.getIndexes().
- Map each existing index to the queries it serves.
Missing Index Identification
- For each discovered query, determine the optimal index strategy.
- Identify
WHERE, ORDER BY, GROUP BY, and JOIN ON columns that lack supporting indexes.
- Recommend compound indexes where multiple columns are filtered or sorted together.
- For MongoDB, consider field order in compound indexes to match query patterns.
Inefficient Index Detection
- Identify indexes with poor selectivity (e.g., boolean columns indexed alone).
- Detect over-broad indexes that could be narrowed with a prefix or partial index.
- Flag indexes whose column order does not match the most common query patterns.
Redundant / Unused Index Detection
- Identify indexes that are strict prefixes of other compound indexes (and therefore redundant).
- Detect indexes on columns never referenced in any query path.
- Flag duplicate indexes (same columns, same order).
Recommendation & Justification
- For each recommendation, explain:
- What: The exact index to add, modify, or drop.
- Why: The query it serves and the performance problem it solves.
- Impact: Expected improvement (e.g., "converts a full collection scan to an index seek on ~50k documents").
- Trade-off: Write-performance cost or storage overhead, if relevant.
Migration Script Generation
- Provide ready-to-use migration or index creation scripts.
- For Laravel: generate a complete migration file using
Schema::table with $table->index() or $table->unique().
- For MongoDB: provide
db.collection.createIndex() commands or an equivalent migration.
- For raw SQL: provide
CREATE INDEX / DROP INDEX statements.
- Include a rollback /
down() method for every migration.
Indexing Review Output Format
Present the indexing review in a structured table per table/collection:
### Indexing Review: `<table_name>`
| # | Type | Columns / Fields | Rationale | Impact |
|---|-------------|----------------------------|----------------------------------------|-----------------------------------------|
| 1 | ADD INDEX | `status, created_at` | Filters on status + date sort | Eliminates full scan on 100k+ rows |
| 2 | ADD COMPOUND| `tenant_id, category, name`| Multi-tenant filtered listing | Index seek instead of collscan |
| 3 | DROP INDEX | `idx_old_status` | Redundant — prefix of index #1 | Saves ~2MB storage, reduces write cost |
| 4 | MODIFY | `idx_name` → add `deleted_at` | Soft-delete queries not covered | Avoids fetching trashed records |
Followed by the migration script:
// Example Laravel migration
public function up(): void
{
Schema::table('components', function (Blueprint $table) {
$table->index(['status', 'created_at'], 'idx_components_status_created');
$table->index(['tenant_id', 'category', 'name'], 'idx_components_tenant_cat_name');
$table->dropIndex('idx_old_status');
});
}
public function down(): void
{
Schema::table('components', function (Blueprint $table) {
$table->dropIndex('idx_components_status_created');
$table->dropIndex('idx_components_tenant_cat_name');
$table->index(['status'], 'idx_old_status');
});
}
Best Practices
- Comprehensive Verification: Use automated tests and manual verification for all affected paths. Provide explicit terminal readout blocks proving execution paths.
- Maintain Stability: Treat the current stable state as sacred; change it only with full awareness.
- Database Strategy: Avoid expensive table scans; leverage existing architecture or propose minimal, high-impact improvements.
- Index Discipline: Every new query path must have a corresponding index justification. Every dropped index must be confirmed unused.
1---2name: ask-impact-sentinel3description: Guidelines for impact analysis, breaking change detection, strategic database design, and comprehensive database indexing review.4---56# Impact Sentinel78A skill focused on impact analysis, breaking change detection, strategic database design, and comprehensive database indexing review.910<critical_constraints>11- ❌ NEVER introduce breaking changes to shared functions without verifying all dependents.12- ❌ NEVER optimize code at the expense of existing functionality or stability.13- ❌ DO NOT perform database operations without considering performance and indexing.14- ❌ NEVER skip the indexing review when a feature touches database queries.15- ✅ ALWAYS identify dependencies before modifying core logic.16- ✅ ALWAYS ensure optimizations are intelligent and verified.17- ✅ ALWAYS use strategic database access and query design.18- ✅ ALWAYS perform a full indexing review covering all related models, services, repositories, and tables — not just the modified controller.19</critical_constraints>2021<heuristics>22- If modifying a shared function → Run full dependency check first.23- If optimizing → Verify "Before vs After" performance and correctness.24- If accessing database → Check for missing indexes or potential N+1 issues.25- If any feature touches a database query → Execute the full Database Indexing Review protocol.26- If breaking change is unavoidable → Propose a migration path or versioned API.27- If finalizing a system deployment → You MUST execute live automated validations (Syntax & Terminal Routing).28</heuristics>2930## Purpose3132The `ask-impact-sentinel` skill guides AI agents to think critically about the consequences of their changes. It ensures that optimizations don't break existing functionality and that database interactions are designed for performance and reliability.3334## Usage3536Apply this skill when:37- Modifying core functions or shared utilities.38- Refactoring existing logic that has many dependencies.39- Designing or optimizing database schemas and queries.40- Adding, modifying, or reviewing any feature that involves database reads or writes.41- Preparing for a release where stability is paramount.4243### Core Protocol44451. **Impact Analysis**: Identify downstream effects of every code change.462. **Regression Prevention**: Validate that existing features remain functional.473. **Automated Validation**: Before clearing any code for production, you must explicitly run backend checks:48 - **Syntax & Core Framework Validation**: Run strict framework linting using the CLI (e.g. `php -l path/to/file.php` or `npm run lint`).49 - **Web Routing & Status Code Validation**: Spin up terminal clients to internally ping root routes directly from the framework engine to confirm HTTP 200 statuses and ensure global middlewares didn't crash the stack (e.g. for Laravel: `php artisan tinker --execute="echo app()->handle(Illuminate\Http\Request::create('/', 'GET'))->getStatusCode();"`).504. **Intelligent Optimization**: Focus on high-impact areas without introducing side effects.515. **Strategic Data Access**: Prioritize efficient query design and database best practices.526. **Database Indexing Review**: For every module and controller touched, execute a comprehensive indexing analysis (see dedicated section below).5354## Examples5556### Before Impact Analysis57```python58# Modifying a shared utility without checking dependents59def get_user_data(user_id):60 return db.query("SELECT * FROM users WHERE id = ?", user_id)61```6263### After Impact Analysis64```python65# Checking dependents and ensuring no breaking changes66def get_user_data(user_id):67 # Verified that 5 other modules use this. 68 # Adding a cache layer instead of changing the return structure.69 data = redis.get(f"user:{user_id}")70 if not data:71 data = db.query("SELECT * FROM users WHERE id = ?", user_id)72 redis.set(f"user:{user_id}", data)73 return data74```7576## Database Indexing Review Protocol7778For **every** module and controller the sentinel works on, a comprehensive database indexing review is **mandatory**. This analysis must extend beyond the modified file to cover **all related models, services, repositories, and database tables** involved in the request.7980### Scope of Analysis8182When triggered, the indexing review must cover:83- The modified controller or module itself.84- All Eloquent/ORM models referenced directly or indirectly.85- Service classes and repository layers that execute queries on behalf of the controller.86- Database tables involved in joins, subqueries, and relationship eager-loads.87- Scheduled jobs, observers, or event listeners that query the same tables.8889### Step-by-Step Procedure90911. **Query Discovery**92 - Trace every database query executed by the feature (including relationships, scopes, and raw queries).93 - List each query with its origin (model, service, repository, or raw statement).94 - Flag N+1 patterns, full-table scans, and unoptimized joins.95962. **Existing Index Audit**97 - Retrieve the current index definitions for every involved table.98 - For SQL databases, run or simulate `SHOW INDEX FROM <table>` (MySQL) or `\d <table>` (PostgreSQL).99 - For MongoDB, inspect `db.collection.getIndexes()`.100 - Map each existing index to the queries it serves.1011023. **Missing Index Identification**103 - For each discovered query, determine the optimal index strategy.104 - Identify `WHERE`, `ORDER BY`, `GROUP BY`, and `JOIN ON` columns that lack supporting indexes.105 - Recommend **compound indexes** where multiple columns are filtered or sorted together.106 - For MongoDB, consider field order in compound indexes to match query patterns.1071084. **Inefficient Index Detection**109 - Identify indexes with poor selectivity (e.g., boolean columns indexed alone).110 - Detect over-broad indexes that could be narrowed with a prefix or partial index.111 - Flag indexes whose column order does not match the most common query patterns.1121135. **Redundant / Unused Index Detection**114 - Identify indexes that are strict prefixes of other compound indexes (and therefore redundant).115 - Detect indexes on columns never referenced in any query path.116 - Flag duplicate indexes (same columns, same order).1171186. **Recommendation & Justification**119 - For each recommendation, explain:120 - **What**: The exact index to add, modify, or drop.121 - **Why**: The query it serves and the performance problem it solves.122 - **Impact**: Expected improvement (e.g., "converts a full collection scan to an index seek on ~50k documents").123 - **Trade-off**: Write-performance cost or storage overhead, if relevant.1241257. **Migration Script Generation**126 - Provide ready-to-use migration or index creation scripts.127 - For Laravel: generate a complete migration file using `Schema::table` with `$table->index()` or `$table->unique()`.128 - For MongoDB: provide `db.collection.createIndex()` commands or an equivalent migration.129 - For raw SQL: provide `CREATE INDEX` / `DROP INDEX` statements.130 - Include a rollback / `down()` method for every migration.131132### Indexing Review Output Format133134Present the indexing review in a structured table per table/collection:135136```markdown137### Indexing Review: `<table_name>`138139| # | Type | Columns / Fields | Rationale | Impact |140|---|-------------|----------------------------|----------------------------------------|-----------------------------------------|141| 1 | ADD INDEX | `status, created_at` | Filters on status + date sort | Eliminates full scan on 100k+ rows |142| 2 | ADD COMPOUND| `tenant_id, category, name`| Multi-tenant filtered listing | Index seek instead of collscan |143| 3 | DROP INDEX | `idx_old_status` | Redundant — prefix of index #1 | Saves ~2MB storage, reduces write cost |144| 4 | MODIFY | `idx_name` → add `deleted_at` | Soft-delete queries not covered | Avoids fetching trashed records |145```146147Followed by the migration script:148149```php150// Example Laravel migration151public function up(): void152{153 Schema::table('components', function (Blueprint $table) {154 $table->index(['status', 'created_at'], 'idx_components_status_created');155 $table->index(['tenant_id', 'category', 'name'], 'idx_components_tenant_cat_name');156 $table->dropIndex('idx_old_status');157 });158}159160public function down(): void161{162 Schema::table('components', function (Blueprint $table) {163 $table->dropIndex('idx_components_status_created');164 $table->dropIndex('idx_components_tenant_cat_name');165 $table->index(['status'], 'idx_old_status');166 });167}168```169170## Best Practices171172- **Comprehensive Verification**: Use automated tests and manual verification for all affected paths. Provide explicit terminal readout blocks proving execution paths.173- **Maintain Stability**: Treat the current stable state as sacred; change it only with full awareness.174- **Database Strategy**: Avoid expensive table scans; leverage existing architecture or propose minimal, high-impact improvements.175- **Index Discipline**: Every new query path must have a corresponding index justification. Every dropped index must be confirmed unused.