Back to loops
Databasemanual triggermarkdown-export Hardened

D1 Query Index Audit

A performance and reliability loop for Cloudflare D1 applications where query shape matters.

Use loop copies the kickoff prompt. Copy Markdown and Download loop include the complete Markdown page with context, source attribution, anchors, and guardrails. Cursor / Claude Code buttons prepare the shorter kickoff prompt only.

Run shape

Supported agents

CursorClaude CodeCodex

Goal

Keep public D1 queries indexed, bounded, and SSR-safe.

Feedback gate

rg -n "select(|where(|limit(" src/modules src/routes

Stop condition

Hot list/detail queries have matching indexes and bounded result sizes.

Do not weaken, skip, delete, or rewrite the validation command to force success.
Do not claim completion until the stated exit condition is actually satisfied.
If blocked, report the blocker, evidence, and next safest action instead of gaming the metric.
Required context

Give the agent these inputs before it starts the loop. This keeps discovery bounded and prevents vague retries.

Hot routes.
Query filters.
Expected page sizes.
Required tools

The loop assumes these commands or integrations are available. Missing tools should be reported as blockers, not ignored.

schema files
service functions
query logs optional
How to run

Two separate pieces: the kickoff prompt starts the loop, while the downloaded Markdown carries the complete reference page.

1. Copy or download

Use the kickoff for a fast agent run. Download the full Markdown when you need source, context, and attribution in one file.

2. Paste into the agent

Start a fresh agent session in the target repo and provide the requested project context if the loop asks for it.

3. Let it self-pace

The agent should act, check evidence, retry only when the gate fails, and stop at the stated exit condition.

manual triggerDatabase Step flow
Manual start
Find public queries
Map filters to indexes
Check result bounds
Patch schema/service
Feedback gate
Goal complete with evidence
not done → return to next actiondone → exit condition met
Manual startFind public queriesMap filters to indexesCheck result boundsPatch schema/serviceFeedback gatedoneGoal complete with evidencenot done
Action checklist

The diagram shows the order. This checklist keeps only the action, command, and failure handling needed during a real pass.

1. Find public queries

Search routes and modules for D1-backed queries.

rg -n "select(|where(|limit(" src/modules src/routes

2. Map filters to indexes

Compare where/order filters to schema indexes.

3. Check result bounds

Ensure lists paginate and detail queries fetch limited related records.

4. Patch schema/service

Add indexes or reduce query fanout where appropriate.

Kickoff prompt

This is the text copied by Use loop. It is intentionally shorter than the Markdown export.

Audit D1-backed public queries for indexes, pagination, N+1 patterns, and SSR safety. Propose or implement targeted fixes.
Goal: Keep public D1 queries indexed, bounded, and SSR-safe.
Check command: rg -n "select(|where(|limit(" src/modules src/routes
Exit condition: Hot list/detail queries have matching indexes and bounded result sizes.
Max iterations: 4
Guardrails:
- Do not weaken, skip, delete, or rewrite the validation command to force success.
- Do not claim completion until the stated exit condition is actually satisfied.
- If blocked, report the blocker, evidence, and next safest action instead of gaming the metric.
- Do not add broad unbounded queries to SEO pages. Keep public pages SSR-friendly.

Quality

86/100

Safety

91/100

Expected output

Index and query audit with concrete schema/service fixes.

Related loops

Browse all
Databasemanual trigger Hardened

Database Migration Review

Review schema and migration changes for destructive operations, D1 compatibility, indexes, and rollback risk.

CursorClaude CodeCodex
databasedrizzled1migration

Kickoff preview

Review database schema and migration changes for D1 compatibility, destructive operations, indexes, and rollback risk. Generate but do not apply production migrations without approval.
Goal: Ensure database changes are safe for development and production migration paths.
Check command: pnpm db:generate
Exit condition: Migration SQL is reviewed and no unexpected destructive operations remain.
Max iterations: 4
Guardrails:
- Do not weaken, skip, delete, or rewrite the validation command to force success.
- Do not claim completion until the stated exit condition is actually satisfied.
- If blocked, report the blocker, evidence, and next safest action instead of gaming the metric.
- Do not apply production migrations without human review. Do not run destructive SQL automatically.
View
DevOpsmanual trigger Hardened

Cloudflare Worker Smoke Test

Verify a Cloudflare Workers deployment, D1 binding, static assets, and route behavior with targeted smoke checks.

Claude CodeCodexGemini CLIOpenCode
cloudflare-workersd1smoke-test

Kickoff preview

Run the Cloudflare build, verify the deployed Worker URL, D1-dependent pages, sitemap, robots, and static assets. Report exact failures.
Goal: Prove the Cloudflare Worker deployment is serving critical routes with correct bindings.
Check command: pnpm cf:build
Exit condition: Cloudflare build and deployed smoke checks pass.
Max iterations: 4
Guardrails:
- Do not weaken, skip, delete, or rewrite the validation command to force success.
- Do not claim completion until the stated exit condition is actually satisfied.
- If blocked, report the blocker, evidence, and next safest action instead of gaming the metric.
- Do not expose Cloudflare tokens or account IDs in public output.
View
SEOmanual trigger Hardened

Programmatic SEO Page QA Loop

Review generated SEO pages for thin content, duplicate metadata, broken internal links, and missing structured data.

CursorClaude CodeCodex
programmatic-seoqualitythin-content

Kickoff preview

Audit a sample of generated SEO pages for uniqueness, helpfulness, metadata, internal links, and schema. Fix template/data issues before publishing at scale.
Goal: Ensure template-generated pages provide distinct value and are safe to index.
Check command: curl -sL $URL
Exit condition: Sampled generated pages have unique metadata, useful body content, and valid internal links.
Max iterations: 5
Guardrails:
- Do not weaken, skip, delete, or rewrite the validation command to force success.
- Do not claim completion until the stated exit condition is actually satisfied.
- If blocked, report the blocker, evidence, and next safest action instead of gaming the metric.
- Do not create large numbers of thin pages solely to manipulate search ranking.
View
CImanual trigger Hardened

Ship PR Until Green

Implement a scoped change, open or update a pull request, inspect CI, and continue until all required PR checks pass.

CursorClaude CodeCodex
pull-requestcigithub-actionsverification

Kickoff preview

Take this branch to a green pull request. Implement the requested change, run local verification, open or update the PR, run `gh pr checks`, inspect failures, fix root causes, and repeat until every required check passes or you hit the iteration cap.
Goal: Open or update a pull request and stop only when all required PR checks are green.
Check command: gh pr checks
Exit condition: All required pull request checks are successful and the PR is ready for review or merge.
Max iterations: 10
Guardrails:
- Do not weaken, skip, delete, or rewrite the validation command to force success.
- Do not claim completion until the stated exit condition is actually satisfied.
- If blocked, report the blocker, evidence, and next safest action instead of gaming the metric.
- Do not disable required checks, edit loops to skip jobs, or remove tests to make CI green.
- Do not merge the PR unless the user explicitly asked for merge authority.
View