@musashishao/agent-kit 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agent/agents/backend-specialist.md +263 -0
- package/.agent/agents/database-architect.md +226 -0
- package/.agent/agents/debugger.md +225 -0
- package/.agent/agents/devops-engineer.md +242 -0
- package/.agent/agents/documentation-writer.md +104 -0
- package/.agent/agents/explorer-agent.md +73 -0
- package/.agent/agents/frontend-specialist.md +556 -0
- package/.agent/agents/game-developer.md +162 -0
- package/.agent/agents/mobile-developer.md +377 -0
- package/.agent/agents/orchestrator.md +416 -0
- package/.agent/agents/penetration-tester.md +188 -0
- package/.agent/agents/performance-optimizer.md +187 -0
- package/.agent/agents/project-planner.md +403 -0
- package/.agent/agents/security-auditor.md +170 -0
- package/.agent/agents/seo-specialist.md +111 -0
- package/.agent/agents/test-engineer.md +158 -0
- package/.agent/mcp/README.md +69 -0
- package/.agent/mcp/config/mcp-config.json +62 -0
- package/.agent/mcp/config/registry.json +54 -0
- package/.agent/mcp/servers/agent-kit-core/package.json +28 -0
- package/.agent/mcp/servers/agent-kit-core/src/index.ts +455 -0
- package/.agent/mcp/servers/agent-kit-core/tsconfig.json +16 -0
- package/.agent/mcp/servers/agent-kit-fs/package.json +25 -0
- package/.agent/mcp/servers/agent-kit-fs/src/index.ts +399 -0
- package/.agent/mcp/servers/agent-kit-fs/tsconfig.json +16 -0
- package/.agent/mcp/servers/agent-kit-git/package.json +24 -0
- package/.agent/mcp/servers/agent-kit-git/src/index.ts +283 -0
- package/.agent/mcp/servers/agent-kit-git/tsconfig.json +16 -0
- package/.agent/mcp/templates/README.md +49 -0
- package/.agent/mcp/templates/api/README.md.template +45 -0
- package/.agent/mcp/templates/api/src/index.ts.template +185 -0
- package/.agent/mcp/templates/base-package.json.template +27 -0
- package/.agent/mcp/templates/base-tsconfig.json +21 -0
- package/.agent/mcp/templates/custom/src/index.ts.template +133 -0
- package/.agent/mcp/templates/database/src/index.ts.template +273 -0
- package/.agent/mcp/templates/web-scraper/src/index.ts.template +239 -0
- package/.agent/rules/CODEX.md +250 -0
- package/.agent/rules/GEMINI.md +251 -0
- package/.agent/skills/api-patterns/SKILL.md +81 -0
- package/.agent/skills/api-patterns/api-style.md +42 -0
- package/.agent/skills/api-patterns/auth.md +24 -0
- package/.agent/skills/api-patterns/documentation.md +26 -0
- package/.agent/skills/api-patterns/graphql.md +41 -0
- package/.agent/skills/api-patterns/rate-limiting.md +31 -0
- package/.agent/skills/api-patterns/response.md +37 -0
- package/.agent/skills/api-patterns/rest.md +40 -0
- package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
- package/.agent/skills/api-patterns/security-testing.md +122 -0
- package/.agent/skills/api-patterns/trpc.md +41 -0
- package/.agent/skills/api-patterns/versioning.md +22 -0
- package/.agent/skills/app-builder/SKILL.md +75 -0
- package/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/.agent/skills/app-builder/feature-building.md +53 -0
- package/.agent/skills/app-builder/project-detection.md +34 -0
- package/.agent/skills/app-builder/scaffolding.md +118 -0
- package/.agent/skills/app-builder/tech-stack.md +40 -0
- package/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +82 -0
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +100 -0
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +106 -0
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +101 -0
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +93 -0
- package/.agent/skills/architecture/SKILL.md +55 -0
- package/.agent/skills/architecture/context-discovery.md +43 -0
- package/.agent/skills/architecture/examples.md +94 -0
- package/.agent/skills/architecture/pattern-selection.md +68 -0
- package/.agent/skills/architecture/patterns-reference.md +50 -0
- package/.agent/skills/architecture/trade-off-analysis.md +77 -0
- package/.agent/skills/bash-linux/SKILL.md +199 -0
- package/.agent/skills/behavioral-modes/SKILL.md +242 -0
- package/.agent/skills/brainstorming/SKILL.md +163 -0
- package/.agent/skills/brainstorming/dynamic-questioning.md +350 -0
- package/.agent/skills/clean-code/SKILL.md +201 -0
- package/.agent/skills/code-review-checklist/SKILL.md +109 -0
- package/.agent/skills/context-engineering/SKILL.md +74 -0
- package/.agent/skills/context-engineering/examples/advanced_code_request.md +73 -0
- package/.agent/skills/context-engineering/scripts/quality_validator.py +294 -0
- package/.agent/skills/context-engineering/scripts/repo_mapper.py +27 -0
- package/.agent/skills/context-engineering/scripts/skill_checker.py +194 -0
- package/.agent/skills/context-engineering/scripts/token_counter.py +65 -0
- package/.agent/skills/context-engineering/strategies/context-caching.md +50 -0
- package/.agent/skills/context-engineering/strategies/few-shot-examples.md +56 -0
- package/.agent/skills/context-engineering/strategies/skeleton-code.md +59 -0
- package/.agent/skills/context-engineering/strategies/xml-framing.md +57 -0
- package/.agent/skills/database-design/SKILL.md +52 -0
- package/.agent/skills/database-design/database-selection.md +43 -0
- package/.agent/skills/database-design/indexing.md +39 -0
- package/.agent/skills/database-design/migrations.md +48 -0
- package/.agent/skills/database-design/optimization.md +36 -0
- package/.agent/skills/database-design/orm-selection.md +30 -0
- package/.agent/skills/database-design/schema-design.md +56 -0
- package/.agent/skills/database-design/scripts/schema_validator.py +172 -0
- package/.agent/skills/deployment-procedures/SKILL.md +241 -0
- package/.agent/skills/doc.md +177 -0
- package/.agent/skills/docker-expert/SKILL.md +409 -0
- package/.agent/skills/documentation-templates/SKILL.md +194 -0
- package/.agent/skills/frontend-design/SKILL.md +396 -0
- package/.agent/skills/frontend-design/animation-guide.md +331 -0
- package/.agent/skills/frontend-design/color-system.md +311 -0
- package/.agent/skills/frontend-design/decision-trees.md +418 -0
- package/.agent/skills/frontend-design/motion-graphics.md +306 -0
- package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/.agent/skills/frontend-design/typography-system.md +345 -0
- package/.agent/skills/frontend-design/ux-psychology.md +541 -0
- package/.agent/skills/frontend-design/visual-effects.md +383 -0
- package/.agent/skills/game-development/2d-games/SKILL.md +119 -0
- package/.agent/skills/game-development/3d-games/SKILL.md +135 -0
- package/.agent/skills/game-development/SKILL.md +167 -0
- package/.agent/skills/game-development/game-art/SKILL.md +185 -0
- package/.agent/skills/game-development/game-audio/SKILL.md +190 -0
- package/.agent/skills/game-development/game-design/SKILL.md +129 -0
- package/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
- package/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
- package/.agent/skills/game-development/pc-games/SKILL.md +144 -0
- package/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
- package/.agent/skills/game-development/web-games/SKILL.md +150 -0
- package/.agent/skills/geo-fundamentals/SKILL.md +156 -0
- package/.agent/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
- package/.agent/skills/i18n-localization/SKILL.md +154 -0
- package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
- package/.agent/skills/lint-and-validate/SKILL.md +45 -0
- package/.agent/skills/lint-and-validate/scripts/lint_runner.py +172 -0
- package/.agent/skills/lint-and-validate/scripts/type_coverage.py +173 -0
- package/.agent/skills/mcp-builder/SKILL.md +662 -0
- package/.agent/skills/mcp-builder/python-template.md +522 -0
- package/.agent/skills/mcp-builder/tool-patterns.md +642 -0
- package/.agent/skills/mcp-builder/typescript-template.md +361 -0
- package/.agent/skills/mobile-design/SKILL.md +394 -0
- package/.agent/skills/mobile-design/decision-trees.md +516 -0
- package/.agent/skills/mobile-design/mobile-backend.md +491 -0
- package/.agent/skills/mobile-design/mobile-color-system.md +420 -0
- package/.agent/skills/mobile-design/mobile-debugging.md +122 -0
- package/.agent/skills/mobile-design/mobile-design-thinking.md +357 -0
- package/.agent/skills/mobile-design/mobile-navigation.md +458 -0
- package/.agent/skills/mobile-design/mobile-performance.md +767 -0
- package/.agent/skills/mobile-design/mobile-testing.md +356 -0
- package/.agent/skills/mobile-design/mobile-typography.md +433 -0
- package/.agent/skills/mobile-design/platform-android.md +666 -0
- package/.agent/skills/mobile-design/platform-ios.md +561 -0
- package/.agent/skills/mobile-design/scripts/mobile_audit.py +670 -0
- package/.agent/skills/mobile-design/touch-psychology.md +537 -0
- package/.agent/skills/nestjs-expert/SKILL.md +552 -0
- package/.agent/skills/nextjs-best-practices/SKILL.md +203 -0
- package/.agent/skills/nodejs-best-practices/SKILL.md +333 -0
- package/.agent/skills/parallel-agents/SKILL.md +175 -0
- package/.agent/skills/performance-profiling/SKILL.md +143 -0
- package/.agent/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
- package/.agent/skills/plan-writing/SKILL.md +152 -0
- package/.agent/skills/powershell-windows/SKILL.md +167 -0
- package/.agent/skills/prisma-expert/SKILL.md +355 -0
- package/.agent/skills/problem-solving/SKILL.md +556 -0
- package/.agent/skills/problem-solving/collision-zone-thinking.md +285 -0
- package/.agent/skills/problem-solving/inversion-exercise.md +205 -0
- package/.agent/skills/problem-solving/meta-pattern-recognition.md +313 -0
- package/.agent/skills/problem-solving/scale-game.md +300 -0
- package/.agent/skills/problem-solving/simplification-cascades.md +321 -0
- package/.agent/skills/problem-solving/when-stuck.md +146 -0
- package/.agent/skills/python-patterns/SKILL.md +441 -0
- package/.agent/skills/react-patterns/SKILL.md +198 -0
- package/.agent/skills/red-team-tactics/SKILL.md +199 -0
- package/.agent/skills/seo-fundamentals/SKILL.md +129 -0
- package/.agent/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
- package/.agent/skills/server-management/SKILL.md +161 -0
- package/.agent/skills/systematic-debugging/SKILL.md +109 -0
- package/.agent/skills/tailwind-patterns/SKILL.md +269 -0
- package/.agent/skills/tdd-workflow/SKILL.md +149 -0
- package/.agent/skills/testing-patterns/SKILL.md +178 -0
- package/.agent/skills/testing-patterns/scripts/test_runner.py +219 -0
- package/.agent/skills/typescript-expert/SKILL.md +429 -0
- package/.agent/skills/typescript-expert/references/tsconfig-strict.json +92 -0
- package/.agent/skills/typescript-expert/references/typescript-cheatsheet.md +383 -0
- package/.agent/skills/typescript-expert/references/utility-types.ts +335 -0
- package/.agent/skills/typescript-expert/scripts/ts_diagnostic.py +203 -0
- package/.agent/skills/ui-ux-pro-max/SKILL.md +351 -0
- package/.agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.agent/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/skills/ui-ux-pro-max/data/styles.csv +59 -0
- package/.agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/scripts/core.py +257 -0
- package/.agent/skills/ui-ux-pro-max/scripts/design_system.py +487 -0
- package/.agent/skills/ui-ux-pro-max/scripts/search.py +76 -0
- package/.agent/skills/vulnerability-scanner/SKILL.md +276 -0
- package/.agent/skills/vulnerability-scanner/checklists.md +121 -0
- package/.agent/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/.agent/skills/webapp-testing/SKILL.md +187 -0
- package/.agent/skills/webapp-testing/scripts/playwright_runner.py +173 -0
- package/.agent/templates/AGENTS.backend.md +230 -0
- package/.agent/templates/AGENTS.md +121 -0
- package/.agent/templates/AGENTS.mobile.md +183 -0
- package/.agent/templates/AGENTS.web.md +192 -0
- package/.agent/workflows/brainstorm.md +113 -0
- package/.agent/workflows/context.md +47 -0
- package/.agent/workflows/create.md +59 -0
- package/.agent/workflows/debug.md +103 -0
- package/.agent/workflows/deploy.md +176 -0
- package/.agent/workflows/enhance.md +63 -0
- package/.agent/workflows/orchestrate.md +237 -0
- package/.agent/workflows/plan.md +89 -0
- package/.agent/workflows/preview.md +80 -0
- package/.agent/workflows/quality.md +89 -0
- package/.agent/workflows/status.md +86 -0
- package/.agent/workflows/test.md +144 -0
- package/.agent/workflows/ui-ux-pro-max.md +250 -0
- package/LICENSE +21 -0
- package/README.md +317 -0
- package/bin/cli.js +1267 -0
- package/index.js +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import tiktoken
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
def count_tokens(text):
|
|
6
|
+
"""
|
|
7
|
+
Count tokens using cl100k_base encoding (used by GPT-4, Claude 3, Gemini).
|
|
8
|
+
This is an approximation for non-OpenAI models but generally accurate enough for budgeting.
|
|
9
|
+
"""
|
|
10
|
+
try:
|
|
11
|
+
encoding = tiktoken.get_encoding("cl100k_base")
|
|
12
|
+
num_tokens = len(encoding.encode(text))
|
|
13
|
+
return num_tokens
|
|
14
|
+
except Exception as e:
|
|
15
|
+
print(f"Error initializing tokenizer: {e}")
|
|
16
|
+
return 0
|
|
17
|
+
|
|
18
|
+
def estimate_cost(tokens, model="gpt-4o"):
|
|
19
|
+
# Approx prices per 1M tokens (as of late 2024/2025)
|
|
20
|
+
pricing = {
|
|
21
|
+
"gpt-4o": 5.00, # Input
|
|
22
|
+
"claude-3-5-sonnet": 3.00,
|
|
23
|
+
"gemini-1.5-pro": 3.50
|
|
24
|
+
}
|
|
25
|
+
price_per_1m = pricing.get(model, 5.00)
|
|
26
|
+
cost = (tokens / 1_000_000) * price_per_1m
|
|
27
|
+
return cost
|
|
28
|
+
|
|
29
|
+
if __name__ == "__main__":
|
|
30
|
+
if len(sys.argv) < 2:
|
|
31
|
+
print("Usage: python token_counter.py <file_or_directory>")
|
|
32
|
+
sys.exit(1)
|
|
33
|
+
|
|
34
|
+
path = sys.argv[1]
|
|
35
|
+
total_tokens = 0
|
|
36
|
+
|
|
37
|
+
if os.path.isfile(path):
|
|
38
|
+
with open(path, 'r', encoding='utf-8', errors='ignore') as f:
|
|
39
|
+
content = f.read()
|
|
40
|
+
total_tokens = count_tokens(content)
|
|
41
|
+
print(f"File: {path}")
|
|
42
|
+
print(f"Tokens: {total_tokens}")
|
|
43
|
+
elif os.path.isdir(path):
|
|
44
|
+
print(f"Scanning directory: {path} (ignoring hidden & node_modules)...")
|
|
45
|
+
for root, dirs, files in os.walk(path):
|
|
46
|
+
dirs[:] = [d for d in dirs if not d.startswith('.') and d != 'node_modules']
|
|
47
|
+
for file in files:
|
|
48
|
+
if file.startswith('.'): continue
|
|
49
|
+
if file.endswith(('.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.ttf')): continue
|
|
50
|
+
|
|
51
|
+
file_path = os.path.join(root, file)
|
|
52
|
+
try:
|
|
53
|
+
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
|
54
|
+
content = f.read()
|
|
55
|
+
tokens = count_tokens(content)
|
|
56
|
+
total_tokens += tokens
|
|
57
|
+
# Optional: Print large files
|
|
58
|
+
if tokens > 5000:
|
|
59
|
+
print(f" - Large file: {file_path} ({tokens} tokens)")
|
|
60
|
+
except Exception as e:
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
print("-" * 30)
|
|
64
|
+
print(f"TOTAL TOKENS: {total_tokens:,}")
|
|
65
|
+
print(f"Est. Input Cost (GPT-4o/Claude-3.5): ~${estimate_cost(total_tokens):.4f}")
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Context Caching Strategy
|
|
2
|
+
|
|
3
|
+
Context Caching is a game-changer for reducing latency and cost when dealing with large contexts (e.g., full documentation, design systems, or large codebases).
|
|
4
|
+
|
|
5
|
+
## How it Works
|
|
6
|
+
|
|
7
|
+
Most LLM providers (Anthropic, Google Gemini) process the prompt sequentially. If the first part of the prompt (the "prefix") is identical across multiple requests, the server can cache the computed attention states of that prefix.
|
|
8
|
+
|
|
9
|
+
- **Hit:** Instant processing, drastically reduced cost (usually ~10% of input price).
|
|
10
|
+
- **Miss:** Normal processing time and cost.
|
|
11
|
+
|
|
12
|
+
## The "Static-First" Rule
|
|
13
|
+
|
|
14
|
+
To maximize cache hits, you must structure your prompt so that **static content is always at the top**.
|
|
15
|
+
|
|
16
|
+
### ✅ Optimized Structure (Cache-Friendly)
|
|
17
|
+
|
|
18
|
+
```xml
|
|
19
|
+
<!-- BLOCK 1: STATIC (Cached) -->
|
|
20
|
+
<system_instructions>...</system_instructions>
|
|
21
|
+
<project_rules>...</project_rules>
|
|
22
|
+
<library_documentation>...</library_documentation>
|
|
23
|
+
<design_system>...</design_system>
|
|
24
|
+
|
|
25
|
+
<!-- BLOCK 2: DYNAMIC (Not Cached) -->
|
|
26
|
+
<chat_history>
|
|
27
|
+
User: Hi
|
|
28
|
+
AI: Hello
|
|
29
|
+
</chat_history>
|
|
30
|
+
<current_file_content>...</current_file_content>
|
|
31
|
+
<new_user_request>...</new_user_request>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### ❌ Bad Structure (Cache-Killer)
|
|
35
|
+
|
|
36
|
+
```xml
|
|
37
|
+
<chat_history>...</chat_history> <!-- Changes every turn! -->
|
|
38
|
+
<system_instructions>...</system_instructions> <!-- Reformatted every time, cache miss! -->
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Implementation Guidelines
|
|
42
|
+
|
|
43
|
+
1. **Breakpoint Management:** Providers usually require a minimum token count to activate caching (e.g., 1024 tokens for Anthropic). Ensure your static block is large enough.
|
|
44
|
+
2. **Immutable Docs:** Treat your documentation and rules as "Immutable". Do not change them dynamically per request unless necessary.
|
|
45
|
+
3. **Cache Control:** Explicitly mark the boundary where caching should stop (if the API supports explicit cache control headers or breakpoints).
|
|
46
|
+
|
|
47
|
+
## Provider Specifics
|
|
48
|
+
|
|
49
|
+
- **Anthropic:** Supports `cache_control: {"type": "ephemeral"}` on specific blocks.
|
|
50
|
+
- **Gemini:** Automatic prefix caching for high-volume endpoints (check current API docs).
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Few-Shot Learning & In-Context Guidance
|
|
2
|
+
|
|
3
|
+
"Show, Don't Tell". LLMs are excellent pattern matchers. Instead of writing 10 paragraphs of rules explaining your coding style, provide **2-3 examples** of code that follows those rules.
|
|
4
|
+
|
|
5
|
+
## The Power of Few-Shot
|
|
6
|
+
|
|
7
|
+
- **Zero-Shot:** "Write a Python function to add numbers." -> *Generic output.*
|
|
8
|
+
- **Few-Shot:** "Here are 3 examples of our project's Python style. Now write a function to add numbers." -> *Output perfectly matches your project's error handling, typing, and docstring standards.*
|
|
9
|
+
|
|
10
|
+
## Constructing "Golden Examples"
|
|
11
|
+
|
|
12
|
+
A Golden Example should demonstrate the **Key Pillars** of your architecture.
|
|
13
|
+
|
|
14
|
+
### Example: "The Robust Handler Pattern"
|
|
15
|
+
|
|
16
|
+
If your project requires all API handlers to have Try-Catch, Logging, and Zod Validation, create an example like this:
|
|
17
|
+
|
|
18
|
+
```xml
|
|
19
|
+
<examples>
|
|
20
|
+
<example>
|
|
21
|
+
<input>Create a handler to update user profile.</input>
|
|
22
|
+
<output>
|
|
23
|
+
<thinking>
|
|
24
|
+
1. Validate input with Zod.
|
|
25
|
+
2. Use UserService for logic.
|
|
26
|
+
3. Wrap in try/catch for global error handler.
|
|
27
|
+
</thinking>
|
|
28
|
+
<code>
|
|
29
|
+
export const updateProfile = async (req: Request, res: Response) => {
|
|
30
|
+
try {
|
|
31
|
+
const schema = z.object({ name: z.string() });
|
|
32
|
+
const data = schema.parse(req.body);
|
|
33
|
+
const user = await UserService.update(req.user.id, data);
|
|
34
|
+
return res.json({ success: true, data: user });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logger.error("Update profile failed", error);
|
|
37
|
+
next(error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
</code>
|
|
41
|
+
</output>
|
|
42
|
+
</example>
|
|
43
|
+
</examples>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## When to use?
|
|
47
|
+
|
|
48
|
+
1. **New File Creation:** Essential. The AI needs to know the "boilerplate" feel.
|
|
49
|
+
2. **Complex Refactoring:** Useful to show "Before vs After" examples.
|
|
50
|
+
3. **Specific Libraries:** If using a niche library, provide examples of its usage.
|
|
51
|
+
|
|
52
|
+
## Strategy: Dynamic Retrieval
|
|
53
|
+
|
|
54
|
+
Don't stuff 50 examples into the context. Use **RAG (Retrieval Augmented Generation)** (or a simple grep-based selector) to find the *most relevant* example for the current task.
|
|
55
|
+
- Task: "Create React Component" -> Inject "React Component Example".
|
|
56
|
+
- Task: "Create SQL Query" -> Inject "SQL Query Example".
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Skeleton Code Strategy
|
|
2
|
+
|
|
3
|
+
**Context Compression** is vital. You rarely need the full implementation of imported modules to understand how to use them. You only need the **Interface** (signatures).
|
|
4
|
+
|
|
5
|
+
## What is Skeleton Code?
|
|
6
|
+
|
|
7
|
+
Skeleton code retains the structure but removes the logic implementation.
|
|
8
|
+
|
|
9
|
+
### Original `auth.service.ts`:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export class AuthService {
|
|
13
|
+
private apiUrl: string;
|
|
14
|
+
|
|
15
|
+
constructor(config: Config) {
|
|
16
|
+
this.apiUrl = config.apiUrl;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async login(credentials: Credentials): Promise<AuthResponse> {
|
|
20
|
+
if (!credentials.email || !credentials.password) {
|
|
21
|
+
throw new Error("Invalid input");
|
|
22
|
+
}
|
|
23
|
+
// ... 50 lines of logic ...
|
|
24
|
+
return response.data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async logout(): Promise<void> {
|
|
28
|
+
// ... logic ...
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Skeleton Version (Token Cost: ~10%):
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
export class AuthService {
|
|
37
|
+
private apiUrl: string;
|
|
38
|
+
constructor(config: Config);
|
|
39
|
+
async login(credentials: Credentials): Promise<AuthResponse>;
|
|
40
|
+
async logout(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## When to use?
|
|
45
|
+
|
|
46
|
+
| File Type | Usage | Strategy |
|
|
47
|
+
| :--- | :--- | :--- |
|
|
48
|
+
| **Active File** | The file being edited | **Full Content** |
|
|
49
|
+
| **Direct Import** | Used by Active File | **Skeleton** (usually) |
|
|
50
|
+
| **Reference** | For understanding patterns | **Skeleton** or **Summary** |
|
|
51
|
+
| **Config/Types** | TypeScript interfaces, Zod schemas | **Full Content** (Critical for correctness) |
|
|
52
|
+
|
|
53
|
+
## Implementation Logic
|
|
54
|
+
|
|
55
|
+
1. Parse the AST (Abstract Syntax Tree) of the code.
|
|
56
|
+
2. Keep `class`, `function` definitions, `interface`, `type`.
|
|
57
|
+
3. Keep Docstrings/JSDoc (optional, usually helpful for semantics).
|
|
58
|
+
4. Remove function bodies `{ ... }`.
|
|
59
|
+
5. Remove private members (unless relevant for inheritance).
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# XML Framing Strategy
|
|
2
|
+
|
|
3
|
+
Use structured XML tags to clearly separate different types of information in the context. This helps the LLM distinguish between instructions, reference data, and user input.
|
|
4
|
+
|
|
5
|
+
## Standard Prompt Structure
|
|
6
|
+
|
|
7
|
+
```xml
|
|
8
|
+
<system_context>
|
|
9
|
+
<role>You are a Senior Software Engineer specialized in [Domain].</role>
|
|
10
|
+
<rules>
|
|
11
|
+
<!-- Project-specific rules (GEMINI.md) -->
|
|
12
|
+
</rules>
|
|
13
|
+
</system_context>
|
|
14
|
+
|
|
15
|
+
<reference_documents>
|
|
16
|
+
<document path="docs/api_spec.md">
|
|
17
|
+
... content ...
|
|
18
|
+
</document>
|
|
19
|
+
<document path="src/types.ts" mode="skeleton">
|
|
20
|
+
... content ...
|
|
21
|
+
</document>
|
|
22
|
+
</reference_documents>
|
|
23
|
+
|
|
24
|
+
<project_structure>
|
|
25
|
+
<!-- Output of repo_mapper.py -->
|
|
26
|
+
</project_structure>
|
|
27
|
+
|
|
28
|
+
<chat_history>
|
|
29
|
+
<!-- Compressed history -->
|
|
30
|
+
</chat_history>
|
|
31
|
+
|
|
32
|
+
<user_request>
|
|
33
|
+
<instruction>
|
|
34
|
+
Refactor the login function to use the new AuthService.
|
|
35
|
+
</instruction>
|
|
36
|
+
<constraints>
|
|
37
|
+
- Do not change the function signature.
|
|
38
|
+
- Add comprehensive error handling.
|
|
39
|
+
</constraints>
|
|
40
|
+
<active_file path="src/auth.ts">
|
|
41
|
+
... full content of the file to edit ...
|
|
42
|
+
</active_file>
|
|
43
|
+
</user_request>
|
|
44
|
+
|
|
45
|
+
<output_format>
|
|
46
|
+
Please provide the solution in the following format:
|
|
47
|
+
1. <thinking>: Analysis of the problem.
|
|
48
|
+
2. <plan>: Step-by-step implementation plan.
|
|
49
|
+
3. <code>: The modified code blocks.
|
|
50
|
+
</output_format>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Key Principles
|
|
54
|
+
|
|
55
|
+
1. **Wrappers matter:** `<code_block>` is better than just backticks for parsing.
|
|
56
|
+
2. **Attributes:** Use attributes like `<file path="...">` so the LLM knows the source.
|
|
57
|
+
3. **Nesting:** Don't go too deep (max 3 levels of nesting) to avoid confusing the attention mechanism.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-design
|
|
3
|
+
description: Database design principles and decision-making. Schema design, indexing strategy, ORM selection, serverless databases.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Database Design
|
|
8
|
+
|
|
9
|
+
> **Learn to THINK, not copy SQL patterns.**
|
|
10
|
+
|
|
11
|
+
## 🎯 Selective Reading Rule
|
|
12
|
+
|
|
13
|
+
**Read ONLY files relevant to the request!** Check the content map, find what you need.
|
|
14
|
+
|
|
15
|
+
| File | Description | When to Read |
|
|
16
|
+
|------|-------------|--------------|
|
|
17
|
+
| `database-selection.md` | PostgreSQL vs Neon vs Turso vs SQLite | Choosing database |
|
|
18
|
+
| `orm-selection.md` | Drizzle vs Prisma vs Kysely | Choosing ORM |
|
|
19
|
+
| `schema-design.md` | Normalization, PKs, relationships | Designing schema |
|
|
20
|
+
| `indexing.md` | Index types, composite indexes | Performance tuning |
|
|
21
|
+
| `optimization.md` | N+1, EXPLAIN ANALYZE | Query optimization |
|
|
22
|
+
| `migrations.md` | Safe migrations, serverless DBs | Schema changes |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## ⚠️ Core Principle
|
|
27
|
+
|
|
28
|
+
- ASK user for database preferences when unclear
|
|
29
|
+
- Choose database/ORM based on CONTEXT
|
|
30
|
+
- Don't default to PostgreSQL for everything
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Decision Checklist
|
|
35
|
+
|
|
36
|
+
Before designing schema:
|
|
37
|
+
|
|
38
|
+
- [ ] Asked user about database preference?
|
|
39
|
+
- [ ] Chosen database for THIS context?
|
|
40
|
+
- [ ] Considered deployment environment?
|
|
41
|
+
- [ ] Planned index strategy?
|
|
42
|
+
- [ ] Defined relationship types?
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Anti-Patterns
|
|
47
|
+
|
|
48
|
+
❌ Default to PostgreSQL for simple apps (SQLite may suffice)
|
|
49
|
+
❌ Skip indexing
|
|
50
|
+
❌ Use SELECT * in production
|
|
51
|
+
❌ Store JSON when structured data is better
|
|
52
|
+
❌ Ignore N+1 queries
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Database Selection (2025)
|
|
2
|
+
|
|
3
|
+
> Choose database based on context, not default.
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What are your requirements?
|
|
9
|
+
│
|
|
10
|
+
├── Full relational features needed
|
|
11
|
+
│ ├── Self-hosted → PostgreSQL
|
|
12
|
+
│ └── Serverless → Neon, Supabase
|
|
13
|
+
│
|
|
14
|
+
├── Edge deployment / Ultra-low latency
|
|
15
|
+
│ └── Turso (edge SQLite)
|
|
16
|
+
│
|
|
17
|
+
├── AI / Vector search
|
|
18
|
+
│ └── PostgreSQL + pgvector
|
|
19
|
+
│
|
|
20
|
+
├── Simple / Embedded / Local
|
|
21
|
+
│ └── SQLite
|
|
22
|
+
│
|
|
23
|
+
└── Global distribution
|
|
24
|
+
└── PlanetScale, CockroachDB, Turso
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Comparison
|
|
28
|
+
|
|
29
|
+
| Database | Best For | Trade-offs |
|
|
30
|
+
|----------|----------|------------|
|
|
31
|
+
| **PostgreSQL** | Full features, complex queries | Needs hosting |
|
|
32
|
+
| **Neon** | Serverless PG, branching | PG complexity |
|
|
33
|
+
| **Turso** | Edge, low latency | SQLite limitations |
|
|
34
|
+
| **SQLite** | Simple, embedded, local | Single-writer |
|
|
35
|
+
| **PlanetScale** | MySQL, global scale | No foreign keys |
|
|
36
|
+
|
|
37
|
+
## Questions to Ask
|
|
38
|
+
|
|
39
|
+
1. What's the deployment environment?
|
|
40
|
+
2. How complex are the queries?
|
|
41
|
+
3. Is edge/serverless important?
|
|
42
|
+
4. Vector search needed?
|
|
43
|
+
5. Global distribution required?
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Indexing Principles
|
|
2
|
+
|
|
3
|
+
> When and how to create indexes effectively.
|
|
4
|
+
|
|
5
|
+
## When to Create Indexes
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Index these:
|
|
9
|
+
├── Columns in WHERE clauses
|
|
10
|
+
├── Columns in JOIN conditions
|
|
11
|
+
├── Columns in ORDER BY
|
|
12
|
+
├── Foreign key columns
|
|
13
|
+
└── Unique constraints
|
|
14
|
+
|
|
15
|
+
Don't over-index:
|
|
16
|
+
├── Write-heavy tables (slower inserts)
|
|
17
|
+
├── Low-cardinality columns
|
|
18
|
+
├── Columns rarely queried
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Index Type Selection
|
|
22
|
+
|
|
23
|
+
| Type | Use For |
|
|
24
|
+
|------|---------|
|
|
25
|
+
| **B-tree** | General purpose, equality & range |
|
|
26
|
+
| **Hash** | Equality only, faster |
|
|
27
|
+
| **GIN** | JSONB, arrays, full-text |
|
|
28
|
+
| **GiST** | Geometric, range types |
|
|
29
|
+
| **HNSW/IVFFlat** | Vector similarity (pgvector) |
|
|
30
|
+
|
|
31
|
+
## Composite Index Principles
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Order matters for composite indexes:
|
|
35
|
+
├── Equality columns first
|
|
36
|
+
├── Range columns last
|
|
37
|
+
├── Most selective first
|
|
38
|
+
└── Match query pattern
|
|
39
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Migration Principles
|
|
2
|
+
|
|
3
|
+
> Safe migration strategy for zero-downtime changes.
|
|
4
|
+
|
|
5
|
+
## Safe Migration Strategy
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
For zero-downtime changes:
|
|
9
|
+
│
|
|
10
|
+
├── Adding column
|
|
11
|
+
│ └── Add as nullable → backfill → add NOT NULL
|
|
12
|
+
│
|
|
13
|
+
├── Removing column
|
|
14
|
+
│ └── Stop using → deploy → remove column
|
|
15
|
+
│
|
|
16
|
+
├── Adding index
|
|
17
|
+
│ └── CREATE INDEX CONCURRENTLY (non-blocking)
|
|
18
|
+
│
|
|
19
|
+
└── Renaming column
|
|
20
|
+
└── Add new → migrate data → deploy → drop old
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Migration Philosophy
|
|
24
|
+
|
|
25
|
+
- Never make breaking changes in one step
|
|
26
|
+
- Test migrations on data copy first
|
|
27
|
+
- Have rollback plan
|
|
28
|
+
- Run in transaction when possible
|
|
29
|
+
|
|
30
|
+
## Serverless Databases
|
|
31
|
+
|
|
32
|
+
### Neon (Serverless PostgreSQL)
|
|
33
|
+
|
|
34
|
+
| Feature | Benefit |
|
|
35
|
+
|---------|---------|
|
|
36
|
+
| Scale to zero | Cost savings |
|
|
37
|
+
| Instant branching | Dev/preview |
|
|
38
|
+
| Full PostgreSQL | Compatibility |
|
|
39
|
+
| Autoscaling | Traffic handling |
|
|
40
|
+
|
|
41
|
+
### Turso (Edge SQLite)
|
|
42
|
+
|
|
43
|
+
| Feature | Benefit |
|
|
44
|
+
|---------|---------|
|
|
45
|
+
| Edge locations | Ultra-low latency |
|
|
46
|
+
| SQLite compatible | Simple |
|
|
47
|
+
| Generous free tier | Cost |
|
|
48
|
+
| Global distribution | Performance |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Query Optimization
|
|
2
|
+
|
|
3
|
+
> N+1 problem, EXPLAIN ANALYZE, optimization priorities.
|
|
4
|
+
|
|
5
|
+
## N+1 Problem
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What is N+1?
|
|
9
|
+
├── 1 query to get parent records
|
|
10
|
+
├── N queries to get related records
|
|
11
|
+
└── Very slow!
|
|
12
|
+
|
|
13
|
+
Solutions:
|
|
14
|
+
├── JOIN → Single query with all data
|
|
15
|
+
├── Eager loading → ORM handles JOIN
|
|
16
|
+
├── DataLoader → Batch and cache (GraphQL)
|
|
17
|
+
└── Subquery → Fetch related in one query
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Query Analysis Mindset
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
Before optimizing:
|
|
24
|
+
├── EXPLAIN ANALYZE the query
|
|
25
|
+
├── Look for Seq Scan (full table scan)
|
|
26
|
+
├── Check actual vs estimated rows
|
|
27
|
+
└── Identify missing indexes
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Optimization Priorities
|
|
31
|
+
|
|
32
|
+
1. **Add missing indexes** (most common issue)
|
|
33
|
+
2. **Select only needed columns** (not SELECT *)
|
|
34
|
+
3. **Use proper JOINs** (avoid subqueries when possible)
|
|
35
|
+
4. **Limit early** (pagination at database level)
|
|
36
|
+
5. **Cache** (when appropriate)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ORM Selection (2025)
|
|
2
|
+
|
|
3
|
+
> Choose ORM based on deployment and DX needs.
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What's the context?
|
|
9
|
+
│
|
|
10
|
+
├── Edge deployment / Bundle size matters
|
|
11
|
+
│ └── Drizzle (smallest, SQL-like)
|
|
12
|
+
│
|
|
13
|
+
├── Best DX / Schema-first
|
|
14
|
+
│ └── Prisma (migrations, studio)
|
|
15
|
+
│
|
|
16
|
+
├── Maximum control
|
|
17
|
+
│ └── Raw SQL with query builder
|
|
18
|
+
│
|
|
19
|
+
└── Python ecosystem
|
|
20
|
+
└── SQLAlchemy 2.0 (async support)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Comparison
|
|
24
|
+
|
|
25
|
+
| ORM | Best For | Trade-offs |
|
|
26
|
+
|-----|----------|------------|
|
|
27
|
+
| **Drizzle** | Edge, TypeScript | Newer, less examples |
|
|
28
|
+
| **Prisma** | DX, schema management | Heavier, not edge-ready |
|
|
29
|
+
| **Kysely** | Type-safe SQL builder | Manual migrations |
|
|
30
|
+
| **Raw SQL** | Complex queries, control | Manual type safety |
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Schema Design Principles
|
|
2
|
+
|
|
3
|
+
> Normalization, primary keys, timestamps, relationships.
|
|
4
|
+
|
|
5
|
+
## Normalization Decision
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
When to normalize (separate tables):
|
|
9
|
+
├── Data is repeated across rows
|
|
10
|
+
├── Updates would need multiple changes
|
|
11
|
+
├── Relationships are clear
|
|
12
|
+
└── Query patterns benefit
|
|
13
|
+
|
|
14
|
+
When to denormalize (embed/duplicate):
|
|
15
|
+
├── Read performance critical
|
|
16
|
+
├── Data rarely changes
|
|
17
|
+
├── Always fetched together
|
|
18
|
+
└── Simpler queries needed
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Primary Key Selection
|
|
22
|
+
|
|
23
|
+
| Type | Use When |
|
|
24
|
+
|------|----------|
|
|
25
|
+
| **UUID** | Distributed systems, security |
|
|
26
|
+
| **ULID** | UUID + sortable by time |
|
|
27
|
+
| **Auto-increment** | Simple apps, single database |
|
|
28
|
+
| **Natural key** | Rarely (business meaning) |
|
|
29
|
+
|
|
30
|
+
## Timestamp Strategy
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
For every table:
|
|
34
|
+
├── created_at → When created
|
|
35
|
+
├── updated_at → Last modified
|
|
36
|
+
└── deleted_at → Soft delete (if needed)
|
|
37
|
+
|
|
38
|
+
Use TIMESTAMPTZ (with timezone) not TIMESTAMP
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Relationship Types
|
|
42
|
+
|
|
43
|
+
| Type | When | Implementation |
|
|
44
|
+
|------|------|----------------|
|
|
45
|
+
| **One-to-One** | Extension data | Separate table with FK |
|
|
46
|
+
| **One-to-Many** | Parent-children | FK on child table |
|
|
47
|
+
| **Many-to-Many** | Both sides have many | Junction table |
|
|
48
|
+
|
|
49
|
+
## Foreign Key ON DELETE
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
├── CASCADE → Delete children with parent
|
|
53
|
+
├── SET NULL → Children become orphans
|
|
54
|
+
├── RESTRICT → Prevent delete if children exist
|
|
55
|
+
└── SET DEFAULT → Children get default value
|
|
56
|
+
```
|