Skip to content

heymegabyte/agent-skills / 06-build-and-slice-loop

build-and-slice-loop

Verified

Use when implementing features or streaming OnePrompt site builds. Complete vertical slices with real content, strict TypeScript and Zod. Parallel section/data work, deterministic assembly, granular patches and immediate valid previews.

FileKindSize
SKILL.mdskill md7.2 KB
admin-dashboard.mdmarkdown5.5 KB
ai-chat-widget.mdmarkdown6.0 KB
blog-and-content-engine.mdmarkdown6.2 KB
build-breaking-rules.mdmarkdown7.4 KB
chat-native-dashboard.mdmarkdown3.6 KB
contact-forms-and-endpoints.mdmarkdown6.7 KB
copilot-and-ai-features.mdmarkdown7.4 KB
custom-error-pages.mdmarkdown4.5 KB
data-tables.mdmarkdown7.7 KB
domain-provisioning.mdmarkdown4.6 KB
easter-eggs.mdmarkdown4.7 KB
empty-states-and-loading.mdmarkdown5.7 KB
file-uploads-and-storage.mdmarkdown6.7 KB
internationalization.mdmarkdown4.3 KB
keyboard-shortcuts-and-command-palette.mdmarkdown6.7 KB
microcopy-library.mdmarkdown8.0 KB
notification-center.mdmarkdown8.4 KB
onboarding-and-first-run.mdmarkdown5.0 KB
pre-digested-builds.mdmarkdown3.6 KB
pwa-kit.mdmarkdown6.8 KB
realtime-and-websockets.mdmarkdown7.2 KB
rich-text-editor.mdmarkdown7.4 KB
site-search.mdmarkdown4.0 KB
stripe-first-donations.mdmarkdown10.7 KB
web-manifest-system.mdmarkdown11.9 KB
webhook-system.mdmarkdown9.5 KB

site-search.md

View on GitHub
---
name: "Site Search"
version: "2.0.0"
updated: "2026-04-23"
description: "Cloudflare AI Search (formerly AutoRAG): hybrid semantic + keyword search, dynamic instances, relevance boosting, multi-tenant via folder-prefix filtering or dedicated namespaces, built-in MCP endpoint for AI agents, Cmd+K modal UI, auto-indexing at deploy."
---

# Site Search (Cloudflare AI Search)

**MANDATORY for every product.** CF AI Search is free, zero-infrastructure, makes products feel premium.

## Wrangler Config

```jsonc
{ "ai_search_namespaces": [{ "binding": "AI_SEARCH", "namespace": "default" }] }
```

## Instance Creation

```typescript
const instance = await env.AI_SEARCH.create({
  id: "projectsites-shared",
  index_method: { vector: true, keyword: true },
  fusion_method: "rrf",
  indexing_options: { keyword_tokenizer: "porter" },
  retrieval_options: { keyword_match_mode: "and" },
});
```

## Multi-Tenant: Folder-Prefix Isolation

```typescript
// Shared instance, filter by site prefix
const results = await instance.search({
  messages: [{ role: "user", content: query }],
  filters: { folder: { $gte: `${siteId}/`, $lt: `${siteId}0` } },
});
```

Range query ensures `site-abc123/` matches but `site-abc1234/` does not.

### Tier Matrix

| Tier | Strategy | Max Pages |
|------|----------|-----------|
| Free | Shared, folder-prefix | 50 |
| Standard | Shared, folder-prefix | 500 |
| Premium | Dedicated instance | 10,000 |
| Enterprise | Dedicated namespace | Unlimited |

## Search API

```typescript
app.get('/api/search', zValidator('query', searchSchema), async (c) => {
  const { q, siteId, limit } = c.req.valid('query');
  const isPremium = (await c.env.KV.get(`site:${siteId}:config`, 'json'))?.tier === 'premium';
  const instance = isPremium ? env.AI_SEARCH.get(`site-${siteId}`) : env.AI_SEARCH.get("projectsites-shared");
  const results = await instance.search({
    messages: [{ role: "user", content: q }],
    ...(isPremium ? {} : { filters: { folder: { $gte: `${siteId}/`, $lt: `${siteId}0` } } }),
    ai_search_options: { max_num_results: limit },
  });
  return c.json({ results: results.results.map((r: any) => ({ url: r.metadata?.url, title: r.metadata?.title, snippet: r.content?.substring(0, 200), score: r.score })) });
});
```

## MCP Endpoint for AI Agents

Expose per-tenant search as MCP tool at `/api/mcp/:siteId`. Returns tool definition + handles tool calls with tenant-scoped search.

## Auto-Index at Deploy

```typescript
async function indexSitePages(env: Env, siteId: string, pages: SitePage[]) {
  const isPremium = (await env.KV.get(`site:${siteId}:config`, 'json'))?.tier === 'premium';
  const instance = isPremium ? env.AI_SEARCH.get(`site-${siteId}`) : env.AI_SEARCH.get('projectsites-shared');
  for (const page of pages) {
    const itemId = isPremium ? `pages/${page.slug}` : `${siteId}/pages/${page.slug}`;
    await instance.items.uploadAndPoll(itemId, page.content, {
      metadata: { title: page.title, url: page.url, description: page.description, updatedAt: new Date().toISOString() },
    });
  }
}
```

## Cmd+K UI

- Keyboard — Cmd/Ctrl+K opens, Escape closes
- Debounced 200ms search on input
- Arrow keys navigate results
- Enter opens
- Shows loading state, empty state

## Cross-Instance Search (Premium)

```typescript
await env.AI_SEARCH.search({ messages: [...], ai_search_options: { instance_ids: ["site-abc", "site-def"] } });
```

## Relevance Boosting

```typescript
boost: [{ field: "timestamp", method: "recency", weight: 1.2 }, { field: "category", method: "match", value: "docs", weight: 1.5 }]
```

## Migration from D1 LIKE

1. Keep same `/api/search` endpoint
2. Replace D1 query with AI Search
3. Add `data-site-id` to `<html>`
4. Run `indexSitePages` on first deploy
5. Remove `search_index` table after verification

## Ownership

- **Owns** — search indexing, multi-tenant isolation, search API, Cmd+K UI, MCP endpoint, auto-indexing, cross-instance search
- **Never owns** — AI chat/conversational (→43), general MCP (→52), deployment (→08)
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall