SuperAPI AI 工具集

firebase-development

编程与开发

查看项目

更新于 10-15 09:28

技能介绍

用途

Firebase Development 是一个用于指导 Firebase 项目开发的技能系统,基于生产项目中的成熟模式,根据检测到的意图路由到专门的子技能。它适用于以下场景:启动新的 Firebase 项目、添加 Cloud Functions 或 Firestore 集合、调试模拟器问题或规则违规、审查 Firebase 代码的安全性和模式、设置多托管配置、实现身份验证(API 密钥或 Firebase Auth)。

主要能力

该技能系统包含四个子技能:

  • firebase-development:project-setup:初始化新的 Firebase 项目。
  • firebase-development:add-feature:添加函数、集合或端点。
  • firebase-development:debug:排查模拟器和运行时问题。
  • firebase-development:validate:审查 Firebase 代码的安全性和模式。

路由逻辑基于关键词匹配:

  • project-setup 关键词:"new firebase project"、"initialize firebase"、"firebase init"、"set up firebase"、"create firebase app"、"start firebase project"。
  • add-feature 关键词:"add function"、"create endpoint"、"new tool"、"add api"、"new collection"、"add feature"、"build"、"implement"。
  • debug 关键词:"error"、"not working"、"debug"、"emulator issue"、"rules failing"、"permission denied"、"troubleshoot"、"deployment failed"。
  • validate 关键词:"review firebase"、"check firebase"、"validate"、"audit firebase"、"look at firebase code"、"security review"。

路由过程:分析请求,检查路由关键词;根据关键词密度匹配最佳子技能;宣布"I'm using the firebase-development:[sub-skill] skill to [action]";加载并执行子技能;若意图不明确,使用 AskUserQuestion 提供四个选项(Project Setup、Add Feature、Debug Issue、Validate Code)让用户选择。

使用方式

该技能系统从三个生产 Firebase 项目中提取模式:

  • oneonone(路径:/Users/dylanr/work/2389/oneonone):Express API、自定义 API 密钥、仅服务器写入。
  • bot-socialmedia(路径:/Users/dylanr/work/2389/bot-socialmedia-server):按域分组的函数、Firebase Auth + 角色。
  • meme-rodeo(路径:/Users/dylanr/work/2389/meme-rodeo):单个函数文件、权益(entitlements)。

模式摘要包括:

多托管设置:三种选项——site: based(多个独立 URL,简单,无需构建协调)、target: based(需要预部署钩子,构建脚本自动运行)、Single + rewrites(较小项目,全部在一个域名下)。详情见 docs/examples/multi-hosting-setup.md。

身份验证:三种模式——自定义 API 密钥(MCP 工具、服务器到服务器,示例 oneonone)、Firebase Auth + 角色(面向用户的应用,示例 bot-socialmedia)、混合(两种模式都需要,Web UI + API 访问)。详情见 docs/examples/api-key-authentication.md。

Cloud Functions 架构:三种模式——Express 应用(带中间件、路由的 API,如 app.post('/mcp', handler))、按域分组(功能丰富的应用,如 posts.ts、journal.ts)、单个文件(最大模块化,每个文件一个函数)。详情见 docs/examples/express-function-architecture.md。

安全模型:两种模型——仅服务器写入(轻写入应用、高安全性,规则简单)、客户端写入 + 验证(高写入量、实时,规则复杂)。对于轻写入应用,强烈推荐仅服务器写入。详情见 docs/examples/firestore-rules-patterns.md。

模拟器优先开发:始终使用模拟器在本地开发:

firebase emulators:start
# Access UI at http://127.0.0.1:4000

firebase.json 中的关键设置:singleProjectMode: true(模拟器协同工作所必需)、ui.enabled: true(访问调试 UI)。详情见 docs/examples/emulator-workflow.md。

现代工具标准:所有 Firebase 项目遵循以下标准——TypeScript(类型安全,tsconfig.json)、vitest(测试,vitest.config.ts)、biome(代码检查和格式化,biome.json)。

ABOUTME 注释模式:每个 TypeScript 文件以 2 行 ABOUTME 注释开头:

// ABOUTME: Brief description of what this file does
// ABOUTME: Second line with additional context

测试要求:单元测试(隔离测试处理程序/工具)、集成测试(在模拟器运行时测试)。每个功能都需要两者。

常见陷阱及解决方案:

  • 模拟器端口被占用:lsof -i :5001,终止进程。
  • Admin SDK 与 Client SDK:Admin 绕过规则,Client 遵守规则。
  • 冷启动延迟:首次调用需要 5-10 秒,正常现象。
  • 数据持久化:使用 Ctrl+C(而非 kill)导出数据。
  • 函数中的 CORS:app.use(cors({ origin: true }))。

适用场景

适用于 Firebase 项目的初始化、功能添加、调试和代码审查。

限制

该技能系统的具体安装方式、收费模式、价格、平台支持等信息暂未提供。