flyee 0.1.0

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.
Files changed (302) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +134 -0
  3. package/bin/install.js +357 -0
  4. package/bridge/bridge.py +1780 -0
  5. package/bridge/local_tracker.py +722 -0
  6. package/core/agents/backend-specialist.md +266 -0
  7. package/core/agents/code-archaeologist.md +106 -0
  8. package/core/agents/database-architect.md +226 -0
  9. package/core/agents/debugger.md +225 -0
  10. package/core/agents/devops-engineer.md +323 -0
  11. package/core/agents/documentation-writer.md +104 -0
  12. package/core/agents/explorer-agent.md +73 -0
  13. package/core/agents/frontend-specialist.md +743 -0
  14. package/core/agents/game-developer.md +162 -0
  15. package/core/agents/mobile-developer.md +377 -0
  16. package/core/agents/orchestrator.md +416 -0
  17. package/core/agents/penetration-tester.md +188 -0
  18. package/core/agents/performance-optimizer.md +187 -0
  19. package/core/agents/product-manager.md +112 -0
  20. package/core/agents/product-owner.md +95 -0
  21. package/core/agents/project-planner.md +470 -0
  22. package/core/agents/qa-automation-engineer.md +103 -0
  23. package/core/agents/security-auditor.md +170 -0
  24. package/core/agents/seo-specialist.md +111 -0
  25. package/core/agents/stitch-designer.md +190 -0
  26. package/core/agents/tdd-reviewer.md +282 -0
  27. package/core/agents/test-engineer.md +158 -0
  28. package/core/scripts/auto_preview.py +148 -0
  29. package/core/scripts/checklist.py +243 -0
  30. package/core/scripts/cost_report.py +149 -0
  31. package/core/scripts/doc-sync-check.py +461 -0
  32. package/core/scripts/parse_user_stories.py +79 -0
  33. package/core/scripts/prepare_notion_updates.py +172 -0
  34. package/core/scripts/print_create_payload.py +18 -0
  35. package/core/scripts/session_manager.py +120 -0
  36. package/core/scripts/task_complete.py +127 -0
  37. package/core/scripts/verify_all.py +327 -0
  38. package/core/skills/analytics-strategy/SKILL.md +128 -0
  39. package/core/skills/api-patterns/SKILL.md +81 -0
  40. package/core/skills/api-patterns/api-style.md +42 -0
  41. package/core/skills/api-patterns/auth.md +24 -0
  42. package/core/skills/api-patterns/documentation.md +26 -0
  43. package/core/skills/api-patterns/graphql.md +41 -0
  44. package/core/skills/api-patterns/rate-limiting.md +31 -0
  45. package/core/skills/api-patterns/response.md +37 -0
  46. package/core/skills/api-patterns/rest.md +40 -0
  47. package/core/skills/api-patterns/scripts/api_validator.py +211 -0
  48. package/core/skills/api-patterns/security-testing.md +122 -0
  49. package/core/skills/api-patterns/trpc.md +41 -0
  50. package/core/skills/api-patterns/versioning.md +22 -0
  51. package/core/skills/app-builder/SKILL.md +75 -0
  52. package/core/skills/app-builder/agent-coordination.md +71 -0
  53. package/core/skills/app-builder/feature-building.md +53 -0
  54. package/core/skills/app-builder/project-detection.md +34 -0
  55. package/core/skills/app-builder/scaffolding.md +118 -0
  56. package/core/skills/app-builder/tech-stack.md +40 -0
  57. package/core/skills/app-builder/templates/SKILL.md +39 -0
  58. package/core/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
  59. package/core/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
  60. package/core/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  61. package/core/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
  62. package/core/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
  63. package/core/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
  64. package/core/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
  65. package/core/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +82 -0
  66. package/core/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +100 -0
  67. package/core/skills/app-builder/templates/nextjs-static/TEMPLATE.md +106 -0
  68. package/core/skills/app-builder/templates/nuxt-app/TEMPLATE.md +101 -0
  69. package/core/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
  70. package/core/skills/app-builder/templates/react-native-app/TEMPLATE.md +93 -0
  71. package/core/skills/architecture/SKILL.md +55 -0
  72. package/core/skills/architecture/context-discovery.md +43 -0
  73. package/core/skills/architecture/examples.md +94 -0
  74. package/core/skills/architecture/pattern-selection.md +68 -0
  75. package/core/skills/architecture/patterns-reference.md +50 -0
  76. package/core/skills/architecture/trade-off-analysis.md +77 -0
  77. package/core/skills/atomic-design/SKILL.md +282 -0
  78. package/core/skills/atomic-design/references/classification-guide.md +132 -0
  79. package/core/skills/atomic-design/references/quality-checklist.md +60 -0
  80. package/core/skills/atomic-design/references/stacks/stack-blade.md +254 -0
  81. package/core/skills/atomic-design/references/stacks/stack-nextjs.md +272 -0
  82. package/core/skills/atomic-design/references/stacks/stack-react.md +239 -0
  83. package/core/skills/atomic-design/references/stacks/stack-vue.md +224 -0
  84. package/core/skills/bash-linux/SKILL.md +199 -0
  85. package/core/skills/behavioral-modes/SKILL.md +242 -0
  86. package/core/skills/brainstorming/SKILL.md +163 -0
  87. package/core/skills/brainstorming/dynamic-questioning.md +373 -0
  88. package/core/skills/checkpointing-patterns/SKILL.md +163 -0
  89. package/core/skills/clean-code/SKILL.md +201 -0
  90. package/core/skills/code-review-checklist/SKILL.md +109 -0
  91. package/core/skills/code-truth-validation/SKILL.md +149 -0
  92. package/core/skills/component-library-discovery/SKILL.md +154 -0
  93. package/core/skills/content-strategy/SKILL.md +222 -0
  94. package/core/skills/context-budget/SKILL.md +155 -0
  95. package/core/skills/context-gathering-patterns/SKILL.md +278 -0
  96. package/core/skills/cost-tracking/SKILL.md +206 -0
  97. package/core/skills/database-design/SKILL.md +52 -0
  98. package/core/skills/database-design/database-selection.md +43 -0
  99. package/core/skills/database-design/indexing.md +39 -0
  100. package/core/skills/database-design/migrations.md +48 -0
  101. package/core/skills/database-design/optimization.md +36 -0
  102. package/core/skills/database-design/orm-selection.md +30 -0
  103. package/core/skills/database-design/schema-design.md +56 -0
  104. package/core/skills/database-design/scripts/schema_validator.py +172 -0
  105. package/core/skills/deployment-procedures/SKILL.md +295 -0
  106. package/core/skills/design-md/README.md +34 -0
  107. package/core/skills/design-md/SKILL.md +172 -0
  108. package/core/skills/design-md/examples/DESIGN.md +154 -0
  109. package/core/skills/design-system-enforcement/SKILL.md +339 -0
  110. package/core/skills/doc.md +177 -0
  111. package/core/skills/document-registry/SKILL.md +130 -0
  112. package/core/skills/documentation-publishing/SKILL.md +174 -0
  113. package/core/skills/documentation-templates/SKILL.md +194 -0
  114. package/core/skills/enhance-prompt/README.md +34 -0
  115. package/core/skills/enhance-prompt/SKILL.md +204 -0
  116. package/core/skills/enhance-prompt/references/KEYWORDS.md +114 -0
  117. package/core/skills/frontend-design/SKILL.md +430 -0
  118. package/core/skills/frontend-design/animation-guide.md +331 -0
  119. package/core/skills/frontend-design/color-system.md +311 -0
  120. package/core/skills/frontend-design/decision-trees.md +418 -0
  121. package/core/skills/frontend-design/motion-graphics.md +306 -0
  122. package/core/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  123. package/core/skills/frontend-design/scripts/ux_audit.py +722 -0
  124. package/core/skills/frontend-design/typography-system.md +345 -0
  125. package/core/skills/frontend-design/ux-psychology.md +541 -0
  126. package/core/skills/frontend-design/visual-effects.md +383 -0
  127. package/core/skills/game-development/2d-games/SKILL.md +119 -0
  128. package/core/skills/game-development/3d-games/SKILL.md +135 -0
  129. package/core/skills/game-development/SKILL.md +167 -0
  130. package/core/skills/game-development/game-art/SKILL.md +185 -0
  131. package/core/skills/game-development/game-audio/SKILL.md +190 -0
  132. package/core/skills/game-development/game-design/SKILL.md +129 -0
  133. package/core/skills/game-development/mobile-games/SKILL.md +108 -0
  134. package/core/skills/game-development/multiplayer/SKILL.md +132 -0
  135. package/core/skills/game-development/pc-games/SKILL.md +144 -0
  136. package/core/skills/game-development/vr-ar/SKILL.md +123 -0
  137. package/core/skills/game-development/web-games/SKILL.md +150 -0
  138. package/core/skills/geo-fundamentals/SKILL.md +156 -0
  139. package/core/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
  140. package/core/skills/git-workflow/SKILL.md +263 -0
  141. package/core/skills/history-check-patterns/SKILL.md +125 -0
  142. package/core/skills/i18n-localization/SKILL.md +154 -0
  143. package/core/skills/i18n-localization/scripts/i18n_checker.py +241 -0
  144. package/core/skills/integration-completeness/SKILL.md +219 -0
  145. package/core/skills/intelligent-routing/SKILL.md +370 -0
  146. package/core/skills/lint-and-validate/SKILL.md +45 -0
  147. package/core/skills/lint-and-validate/scripts/lint_runner.py +173 -0
  148. package/core/skills/lint-and-validate/scripts/type_coverage.py +173 -0
  149. package/core/skills/local-verification/SKILL.md +195 -0
  150. package/core/skills/mcp-builder/SKILL.md +176 -0
  151. package/core/skills/mobile-design/SKILL.md +394 -0
  152. package/core/skills/mobile-design/decision-trees.md +516 -0
  153. package/core/skills/mobile-design/mobile-backend.md +491 -0
  154. package/core/skills/mobile-design/mobile-color-system.md +420 -0
  155. package/core/skills/mobile-design/mobile-debugging.md +122 -0
  156. package/core/skills/mobile-design/mobile-design-thinking.md +357 -0
  157. package/core/skills/mobile-design/mobile-navigation.md +458 -0
  158. package/core/skills/mobile-design/mobile-performance.md +767 -0
  159. package/core/skills/mobile-design/mobile-testing.md +356 -0
  160. package/core/skills/mobile-design/mobile-typography.md +433 -0
  161. package/core/skills/mobile-design/platform-android.md +666 -0
  162. package/core/skills/mobile-design/platform-ios.md +561 -0
  163. package/core/skills/mobile-design/scripts/mobile_audit.py +670 -0
  164. package/core/skills/mobile-design/touch-psychology.md +537 -0
  165. package/core/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +312 -0
  166. package/core/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +240 -0
  167. package/core/skills/nextjs-react-expert/3-server-server-side-performance.md +490 -0
  168. package/core/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +264 -0
  169. package/core/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +581 -0
  170. package/core/skills/nextjs-react-expert/6-rendering-rendering-performance.md +432 -0
  171. package/core/skills/nextjs-react-expert/7-js-javascript-performance.md +684 -0
  172. package/core/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +150 -0
  173. package/core/skills/nextjs-react-expert/SKILL.md +267 -0
  174. package/core/skills/nextjs-react-expert/scripts/convert_rules.py +222 -0
  175. package/core/skills/nextjs-react-expert/scripts/react_performance_checker.py +252 -0
  176. package/core/skills/nodejs-best-practices/SKILL.md +333 -0
  177. package/core/skills/notion-task-patterns/SKILL.md +2529 -0
  178. package/core/skills/page-specifications/SKILL.md +367 -0
  179. package/core/skills/parallel-agents/SKILL.md +175 -0
  180. package/core/skills/performance-profiling/SKILL.md +143 -0
  181. package/core/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
  182. package/core/skills/plan-writing/SKILL.md +190 -0
  183. package/core/skills/powershell-windows/SKILL.md +167 -0
  184. package/core/skills/project-foundation/SKILL.md +117 -0
  185. package/core/skills/project-setup/SKILL.md +141 -0
  186. package/core/skills/project-tracking-patterns/SKILL.md +357 -0
  187. package/core/skills/project-type-discovery/SKILL.md +239 -0
  188. package/core/skills/python-patterns/SKILL.md +441 -0
  189. package/core/skills/qa-test-generation/SKILL.md +156 -0
  190. package/core/skills/react-components/README.md +36 -0
  191. package/core/skills/react-components/SKILL.md +47 -0
  192. package/core/skills/react-components/examples/gold-standard-card.tsx +80 -0
  193. package/core/skills/react-components/package-lock.json +231 -0
  194. package/core/skills/react-components/package.json +16 -0
  195. package/core/skills/react-components/resources/architecture-checklist.md +15 -0
  196. package/core/skills/react-components/resources/component-template.tsx +37 -0
  197. package/core/skills/react-components/resources/stitch-api-reference.md +14 -0
  198. package/core/skills/react-components/resources/style-guide.json +27 -0
  199. package/core/skills/react-components/scripts/fetch-stitch.sh +30 -0
  200. package/core/skills/react-components/scripts/validate.js +68 -0
  201. package/core/skills/red-team-tactics/SKILL.md +199 -0
  202. package/core/skills/remotion/README.md +105 -0
  203. package/core/skills/remotion/SKILL.md +393 -0
  204. package/core/skills/remotion/examples/WalkthroughComposition.tsx +78 -0
  205. package/core/skills/remotion/examples/screens.json +56 -0
  206. package/core/skills/remotion/resources/composition-checklist.md +124 -0
  207. package/core/skills/remotion/resources/screen-slide-template.tsx +123 -0
  208. package/core/skills/remotion/scripts/download-stitch-asset.sh +38 -0
  209. package/core/skills/seo-fundamentals/SKILL.md +129 -0
  210. package/core/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
  211. package/core/skills/server-management/SKILL.md +161 -0
  212. package/core/skills/session-resilience/SKILL.md +199 -0
  213. package/core/skills/shadcn-ui/README.md +248 -0
  214. package/core/skills/shadcn-ui/SKILL.md +326 -0
  215. package/core/skills/shadcn-ui/examples/auth-layout.tsx +177 -0
  216. package/core/skills/shadcn-ui/examples/data-table.tsx +313 -0
  217. package/core/skills/shadcn-ui/examples/form-pattern.tsx +177 -0
  218. package/core/skills/shadcn-ui/resources/component-catalog.md +481 -0
  219. package/core/skills/shadcn-ui/resources/customization-guide.md +516 -0
  220. package/core/skills/shadcn-ui/resources/migration-guide.md +463 -0
  221. package/core/skills/shadcn-ui/resources/setup-guide.md +412 -0
  222. package/core/skills/shadcn-ui/scripts/verify-setup.sh +134 -0
  223. package/core/skills/state-machine/SKILL.md +264 -0
  224. package/core/skills/stitch-loop/README.md +54 -0
  225. package/core/skills/stitch-loop/SKILL.md +203 -0
  226. package/core/skills/stitch-loop/examples/SITE.md +73 -0
  227. package/core/skills/stitch-loop/examples/next-prompt.md +25 -0
  228. package/core/skills/stitch-loop/resources/baton-schema.md +61 -0
  229. package/core/skills/stitch-loop/resources/site-template.md +104 -0
  230. package/core/skills/systematic-debugging/SKILL.md +109 -0
  231. package/core/skills/tailwind-patterns/SKILL.md +284 -0
  232. package/core/skills/tdd-validation/SKILL.md +243 -0
  233. package/core/skills/tdd-workflow/SKILL.md +284 -0
  234. package/core/skills/testing-patterns/SKILL.md +196 -0
  235. package/core/skills/testing-patterns/scripts/test_runner.py +219 -0
  236. package/core/skills/ui-ux-discovery/SKILL.md +329 -0
  237. package/core/skills/ui-validation/SKILL.md +190 -0
  238. package/core/skills/ui-validation/scripts/ui_antipattern_check.py +317 -0
  239. package/core/skills/verification-gate/SKILL.md +205 -0
  240. package/core/skills/vulnerability-scanner/SKILL.md +276 -0
  241. package/core/skills/vulnerability-scanner/checklists.md +121 -0
  242. package/core/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
  243. package/core/skills/web-design-guidelines/SKILL.md +57 -0
  244. package/core/skills/webapp-testing/SKILL.md +187 -0
  245. package/core/skills/webapp-testing/scripts/playwright_runner.py +173 -0
  246. package/core/templates/ARCHITECTURE.template.md +407 -0
  247. package/core/templates/project-resources.example.json +71 -0
  248. package/core/workflows/atomic.md +182 -0
  249. package/core/workflows/brainstorm.md +134 -0
  250. package/core/workflows/check-task.md +242 -0
  251. package/core/workflows/copy-collect.md +306 -0
  252. package/core/workflows/create-agent.md +33 -0
  253. package/core/workflows/create-skill.md +39 -0
  254. package/core/workflows/create-workflow.md +33 -0
  255. package/core/workflows/create.md +92 -0
  256. package/core/workflows/debug.md +186 -0
  257. package/core/workflows/demand.md +443 -0
  258. package/core/workflows/deploy.md +260 -0
  259. package/core/workflows/discovery.md +267 -0
  260. package/core/workflows/document.md +272 -0
  261. package/core/workflows/ds-components.md +296 -0
  262. package/core/workflows/ds-init.md +58 -0
  263. package/core/workflows/ds-refactor.md +245 -0
  264. package/core/workflows/ds-references.md +197 -0
  265. package/core/workflows/ds-styleguide.md +237 -0
  266. package/core/workflows/ds-token-diff.md +103 -0
  267. package/core/workflows/ds-tokens.md +317 -0
  268. package/core/workflows/ds-validate.md +309 -0
  269. package/core/workflows/execute.md +483 -0
  270. package/core/workflows/extract-template.md +278 -0
  271. package/core/workflows/fix-failed-tests.md +160 -0
  272. package/core/workflows/init-project.md +386 -0
  273. package/core/workflows/legacy-project.md +849 -0
  274. package/core/workflows/log.md +97 -0
  275. package/core/workflows/new-project.md +610 -0
  276. package/core/workflows/new-project.md.bak +3292 -0
  277. package/core/workflows/new-task.md +404 -0
  278. package/core/workflows/orchestrate.md +237 -0
  279. package/core/workflows/page-build.md +296 -0
  280. package/core/workflows/plan.md +89 -0
  281. package/core/workflows/prd.md +255 -0
  282. package/core/workflows/preview.md +81 -0
  283. package/core/workflows/review-page.md +304 -0
  284. package/core/workflows/status.md +86 -0
  285. package/core/workflows/stitch.md +226 -0
  286. package/core/workflows/task-complete.md +473 -0
  287. package/core/workflows/task-update.md +163 -0
  288. package/core/workflows/tdd.md +344 -0
  289. package/core/workflows/test.md +251 -0
  290. package/core/workflows/ui-ux-pro-max.md +437 -0
  291. package/core/workflows/ux-mobile-optimize.md +262 -0
  292. package/core/workflows/ux-mobile-validate.md +297 -0
  293. package/engine-files/GEMINI.md +69 -0
  294. package/package.json +47 -0
  295. package/runtime-adapters/antigravity.js +26 -0
  296. package/runtime-adapters/claude.js +57 -0
  297. package/runtime-adapters/codex.js +51 -0
  298. package/runtime-adapters/copilot.js +51 -0
  299. package/runtime-adapters/cursor.js +51 -0
  300. package/runtime-adapters/gemini-cli.js +30 -0
  301. package/runtime-adapters/opencode.js +51 -0
  302. package/runtime-adapters/windsurf.js +51 -0
@@ -0,0 +1,206 @@
1
+ ---
2
+ name: cost-tracking
3
+ description: LLM usage cost monitoring per operation. Local JSONL log, budget alerts per sprint, cost reports. Emits events for Flyee SaaS dashboard visualization when connected.
4
+ ---
5
+
6
+ # Cost Tracking
7
+
8
+ > **Absorbed from:** GSD-2 `auto-budget.ts`, `model-cost-table.ts`
9
+ > **Purpose:** Know how much each task/sprint costs. Set budgets. Get alerts.
10
+
11
+ ---
12
+
13
+ ## 🎯 PURPOSE
14
+
15
+ AI agent usage has real costs (API tokens, compute time). Without tracking:
16
+ - No visibility into per-task cost
17
+ - No way to budget for a sprint
18
+ - No way to optimize expensive operations
19
+ - Surprises on the invoice
20
+
21
+ ---
22
+
23
+ ## 📊 COST LOG
24
+
25
+ **File:** `.flyee/cost-log.jsonl` (gitignored)
26
+
27
+ Append-only JSON Lines format. One entry per operation.
28
+
29
+ ```jsonl
30
+ {"ts":"2026-03-31T17:00:00Z","sprint":"S09","phase":"P02","task":"T03","op":"plan","model":"gemini-2.5-pro","tokens_in":2400,"tokens_out":1800,"cost_usd":0.042,"duration_ms":3200}
31
+ {"ts":"2026-03-31T17:01:00Z","sprint":"S09","phase":"P02","task":"T03","op":"execute","model":"gemini-2.5-pro","tokens_in":8500,"tokens_out":4200,"cost_usd":0.127,"duration_ms":12400}
32
+ {"ts":"2026-03-31T17:05:00Z","sprint":"S09","phase":"P02","task":"T03","op":"verify","model":"gemini-2.5-pro","tokens_in":1200,"tokens_out":600,"cost_usd":0.018,"duration_ms":1800}
33
+ ```
34
+
35
+ ### Entry Fields
36
+
37
+ | Field | Type | Description |
38
+ |-------|------|-------------|
39
+ | `ts` | ISO 8601 | Timestamp |
40
+ | `sprint` | string | Sprint ID (e.g., S09) |
41
+ | `phase` | string | Phase ID (e.g., P02) |
42
+ | `task` | string | Task ID (e.g., T03) |
43
+ | `op` | string | Operation type |
44
+ | `model` | string | LLM model used |
45
+ | `tokens_in` | integer | Input tokens consumed |
46
+ | `tokens_out` | integer | Output tokens generated |
47
+ | `cost_usd` | float | Estimated cost in USD |
48
+ | `duration_ms` | integer | Wall-clock duration |
49
+
50
+ ### Operation Types
51
+
52
+ | Type | Description |
53
+ |------|-------------|
54
+ | `plan` | Task planning / analysis |
55
+ | `execute` | Code generation / implementation |
56
+ | `verify` | Verification gate checks |
57
+ | `debug` | Debugging operations |
58
+ | `review` | Code review |
59
+ | `search` | Codebase search / context loading |
60
+ | `refactor` | Code refactoring |
61
+
62
+ ---
63
+
64
+ ## 💰 BUDGET SYSTEM
65
+
66
+ ### Per-Sprint Budget
67
+
68
+ Set in CONTEXT.md:
69
+
70
+ ```markdown
71
+ # S09 — Blog & CMS
72
+
73
+ ## Budget
74
+ - **Max cost:** $15.00
75
+ - **Alert at:** $12.00 (80%)
76
+ - **Current:** $0.00
77
+ ```
78
+
79
+ ### Budget Alerts
80
+
81
+ ```
82
+ 💰 Cost Report — S09
83
+ Sprint budget: $15.00
84
+ Spent: $12.40 (83%)
85
+ ⚠️ Approaching budget limit!
86
+
87
+ Breakdown by phase:
88
+ P01 Backend API: $3.20 (26%)
89
+ P02 Frontend: $6.80 (55%)
90
+ P03 CMS Admin: $2.40 (19%)
91
+
92
+ Most expensive task: T03 BlogCard — $2.80
93
+ ```
94
+
95
+ ### Alert Levels
96
+
97
+ | Level | Threshold | Action |
98
+ |-------|-----------|--------|
99
+ | ℹ️ Info | 50% | Log only |
100
+ | ⚠️ Warning | 80% | Alert user |
101
+ | 🔴 Critical | 95% | Alert + suggest pausing |
102
+ | 🛑 Over budget | 100% | Alert + require user approval to continue |
103
+
104
+ ---
105
+
106
+ ## 📡 FLYEE SAAS EVENTS
107
+
108
+ When connected to Flyee SaaS (`flyee.json` exists), emit events for dashboard:
109
+
110
+ ### Event: `cost.operation`
111
+
112
+ ```python
113
+ bridge.emit_event("cost.operation", {
114
+ "sprint": "S09",
115
+ "phase": "P02",
116
+ "task": "T03",
117
+ "operation": "execute",
118
+ "model": "gemini-2.5-pro",
119
+ "tokens_in": 8500,
120
+ "tokens_out": 4200,
121
+ "cost_usd": 0.127,
122
+ "duration_ms": 12400
123
+ })
124
+ ```
125
+
126
+ ### Event: `cost.budget_alert`
127
+
128
+ ```python
129
+ bridge.emit_event("cost.budget_alert", {
130
+ "sprint": "S09",
131
+ "budget_usd": 15.00,
132
+ "spent_usd": 12.40,
133
+ "percentage": 83,
134
+ "level": "warning"
135
+ })
136
+ ```
137
+
138
+ ### Event: `cost.sprint_summary`
139
+
140
+ Emitted when sprint completes:
141
+
142
+ ```python
143
+ bridge.emit_event("cost.sprint_summary", {
144
+ "sprint": "S09",
145
+ "total_cost_usd": 14.20,
146
+ "total_tokens_in": 125000,
147
+ "total_tokens_out": 68000,
148
+ "tasks_completed": 12,
149
+ "avg_task_cost_usd": 1.18,
150
+ "most_expensive_task": "T03",
151
+ "most_expensive_cost": 2.80
152
+ })
153
+ ```
154
+
155
+ ---
156
+
157
+ ## 📊 COST REPORT (Local)
158
+
159
+ Generate with:
160
+
161
+ ```bash
162
+ python3 .agent/scripts/cost_report.py
163
+ ```
164
+
165
+ Output:
166
+
167
+ ```
168
+ ═══════════════════════════════════════
169
+ @flyee Cost Report — S09
170
+ ═══════════════════════════════════════
171
+
172
+ Total: $14.20 / $15.00 budget (95%)
173
+ Operations: 42
174
+ Tokens: 125K in / 68K out
175
+
176
+ Phase breakdown:
177
+ ┌────────────┬────────┬───────┬──────────┐
178
+ │ Phase │ Cost │ Tasks │ Avg/Task │
179
+ ├────────────┼────────┼───────┼──────────┤
180
+ │ P01 Backend│ $3.20 │ 3 │ $1.07 │
181
+ │ P02 Front │ $6.80 │ 4 │ $1.70 │
182
+ │ P03 CMS │ $2.40 │ 3 │ $0.80 │
183
+ │ P04 SEO │ $1.80 │ 2 │ $0.90 │
184
+ └────────────┴────────┴───────┴──────────┘
185
+
186
+ Most expensive operations:
187
+ 1. T03 execute — $2.80 (20%)
188
+ 2. T01 plan — $1.20 (8%)
189
+ 3. T05 debug — $1.10 (8%)
190
+ ═══════════════════════════════════════
191
+ ```
192
+
193
+ ---
194
+
195
+ ## ⚡ QUICK REFERENCE
196
+
197
+ ```bash
198
+ # View current costs
199
+ python3 .agent/scripts/cost_report.py
200
+
201
+ # View cost log raw
202
+ tail -20 .flyee/cost-log.jsonl | python3 -m json.tool
203
+
204
+ # Set budget (in CONTEXT.md)
205
+ echo "Budget: $15.00" >> .flyee/sprints/S09/CONTEXT.md
206
+ ```
@@ -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
+ ```
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Schema Validator - Database schema validation
4
+ Validates Prisma schemas and checks for common issues.
5
+
6
+ Usage:
7
+ python schema_validator.py <project_path>
8
+
9
+ Checks:
10
+ - Prisma schema syntax
11
+ - Missing relations
12
+ - Index recommendations
13
+ - Naming conventions
14
+ """
15
+
16
+ import sys
17
+ import json
18
+ import re
19
+ from pathlib import Path
20
+ from datetime import datetime
21
+
22
+ # Fix Windows console encoding
23
+ try:
24
+ sys.stdout.reconfigure(encoding='utf-8', errors='replace')
25
+ except:
26
+ pass
27
+
28
+
29
+ def find_schema_files(project_path: Path) -> list:
30
+ """Find database schema files."""
31
+ schemas = []
32
+
33
+ # Prisma schema
34
+ prisma_files = list(project_path.glob('**/prisma/schema.prisma'))
35
+ schemas.extend([('prisma', f) for f in prisma_files])
36
+
37
+ # Drizzle schema files
38
+ drizzle_files = list(project_path.glob('**/drizzle/*.ts'))
39
+ drizzle_files.extend(project_path.glob('**/schema/*.ts'))
40
+ for f in drizzle_files:
41
+ if 'schema' in f.name.lower() or 'table' in f.name.lower():
42
+ schemas.append(('drizzle', f))
43
+
44
+ return schemas[:10] # Limit
45
+
46
+
47
+ def validate_prisma_schema(file_path: Path) -> list:
48
+ """Validate Prisma schema file."""
49
+ issues = []
50
+
51
+ try:
52
+ content = file_path.read_text(encoding='utf-8', errors='ignore')
53
+
54
+ # Find all models
55
+ models = re.findall(r'model\s+(\w+)\s*{([^}]+)}', content, re.DOTALL)
56
+
57
+ for model_name, model_body in models:
58
+ # Check naming convention (PascalCase)
59
+ if not model_name[0].isupper():
60
+ issues.append(f"Model '{model_name}' should be PascalCase")
61
+
62
+ # Check for id field
63
+ if '@id' not in model_body and 'id' not in model_body.lower():
64
+ issues.append(f"Model '{model_name}' might be missing @id field")
65
+
66
+ # Check for createdAt/updatedAt
67
+ if 'createdAt' not in model_body and 'created_at' not in model_body:
68
+ issues.append(f"Model '{model_name}' missing createdAt field (recommended)")
69
+
70
+ # Check for @relation without fields
71
+ relations = re.findall(r'@relation\([^)]*\)', model_body)
72
+ for rel in relations:
73
+ if 'fields:' not in rel and 'references:' not in rel:
74
+ pass # Implicit relation, ok
75
+
76
+ # Check for @@index suggestions
77
+ foreign_keys = re.findall(r'(\w+Id)\s+\w+', model_body)
78
+ for fk in foreign_keys:
79
+ if f'@@index([{fk}])' not in content and f'@@index(["{fk}"])' not in content:
80
+ issues.append(f"Consider adding @@index([{fk}]) for better query performance in {model_name}")
81
+
82
+ # Check for enum definitions
83
+ enums = re.findall(r'enum\s+(\w+)\s*{', content)
84
+ for enum_name in enums:
85
+ if not enum_name[0].isupper():
86
+ issues.append(f"Enum '{enum_name}' should be PascalCase")
87
+
88
+ except Exception as e:
89
+ issues.append(f"Error reading schema: {str(e)[:50]}")
90
+
91
+ return issues
92
+
93
+
94
+ def main():
95
+ project_path = Path(sys.argv[1] if len(sys.argv) > 1 else ".").resolve()
96
+
97
+ print(f"\n{'='*60}")
98
+ print(f"[SCHEMA VALIDATOR] Database Schema Validation")
99
+ print(f"{'='*60}")
100
+ print(f"Project: {project_path}")
101
+ print(f"Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
102
+ print("-"*60)
103
+
104
+ # Find schema files
105
+ schemas = find_schema_files(project_path)
106
+ print(f"Found {len(schemas)} schema files")
107
+
108
+ if not schemas:
109
+ output = {
110
+ "script": "schema_validator",
111
+ "project": str(project_path),
112
+ "schemas_checked": 0,
113
+ "issues_found": 0,
114
+ "passed": True,
115
+ "message": "No schema files found"
116
+ }
117
+ print(json.dumps(output, indent=2))
118
+ sys.exit(0)
119
+
120
+ # Validate each schema
121
+ all_issues = []
122
+
123
+ for schema_type, file_path in schemas:
124
+ print(f"\nValidating: {file_path.name} ({schema_type})")
125
+
126
+ if schema_type == 'prisma':
127
+ issues = validate_prisma_schema(file_path)
128
+ else:
129
+ issues = [] # Drizzle validation could be added
130
+
131
+ if issues:
132
+ all_issues.append({
133
+ "file": str(file_path.name),
134
+ "type": schema_type,
135
+ "issues": issues
136
+ })
137
+
138
+ # Summary
139
+ print("\n" + "="*60)
140
+ print("SCHEMA ISSUES")
141
+ print("="*60)
142
+
143
+ if all_issues:
144
+ for item in all_issues:
145
+ print(f"\n{item['file']} ({item['type']}):")
146
+ for issue in item["issues"][:5]: # Limit per file
147
+ print(f" - {issue}")
148
+ if len(item["issues"]) > 5:
149
+ print(f" ... and {len(item['issues']) - 5} more issues")
150
+ else:
151
+ print("No schema issues found!")
152
+
153
+ total_issues = sum(len(item["issues"]) for item in all_issues)
154
+ # Schema issues are warnings, not failures
155
+ passed = True
156
+
157
+ output = {
158
+ "script": "schema_validator",
159
+ "project": str(project_path),
160
+ "schemas_checked": len(schemas),
161
+ "issues_found": total_issues,
162
+ "passed": passed,
163
+ "issues": all_issues
164
+ }
165
+
166
+ print("\n" + json.dumps(output, indent=2))
167
+
168
+ sys.exit(0)
169
+
170
+
171
+ if __name__ == "__main__":
172
+ main()