我們要將「即時聊天室」專案轉化為一鍵生成的 Skill!
耗時: 30-60 分鐘
耗時: 2 分鐘
在設計 Skill 之前,我們先來分析這個專案的組成。
index.html
包含完整的 HTML + CSS + JavaScript
約 750 行程式碼
firebaseConfig 物件
firebaseConfig 需要替換,其他程式碼都是固定的!
設計一個好的 Skill,需要清楚定義每個步驟。
resources/chat-template.html 讀取完整程式碼
{{FIREBASE_CONFIG}} 替換為使用者提供的設定
好的架構讓 Skill 更易於維護和擴展。兩種 AI 工具的結構相同:
Frontmatter 決定了這個 Skill 何時被觸發。
---
name: firebase-chat-generator
description: "Build Firebase chat room with real-time messaging.
Actions: create chat, build chatroom, make chat app,
建立聊天室, 聊天室專案, 即時通訊.
Tech: Firebase Auth, Firestore, Google Login, real-time sync."
---
當使用者說以下任一句話,AI 就會自動啟用這個 Skill:
開頭說明與前置檢查。
# Firebase Chat Generator
本技能用於快速生成 Firebase 即時聊天室專案。
生成的聊天室包含 Google 登入、即時訊息同步等完整功能。
## Prerequisites (前置需求)
Before proceeding, you MUST confirm the user has:
1. **Firebase Project** - Created at https://console.firebase.google.com
2. **Google Authentication** - Enabled in Authentication > Sign-in method
3. **Firestore Database** - Created in Build > Firestore Database
4. **Firebase Config** - The configuration object from Project Settings
If user doesn't have these ready, guide them to complete
the setup first before generating the chat application.
收集使用者的 Firebase Config。
## Step 1: Collect Firebase Config
You MUST ask the user for their Firebase configuration.
Display this prompt:
"""
請提供您的 Firebase Config,您可以在以下位置找到:
Firebase Console → 專案設定(齒輪圖示) → 一般 → 您的應用程式 → SDK 設定和配置
我需要以下資訊:
- apiKey
- authDomain
- projectId
- storageBucket
- messagingSenderId
- appId
"""
### Config Format Example
The user should provide something like:
```javascript
{
apiKey: "AIzaSy...",
authDomain: "my-project.firebaseapp.com",
projectId: "my-project",
storageBucket: "my-project.appspot.com",
messagingSenderId: "123456789",
appId: "1:123456789:web:abc123"
}
```
檔案生成與後續說明。
## Step 2: Generate Chat Application
1. Read the template file: `resources/chat-template.html`
2. Find the placeholder: `{{FIREBASE_CONFIG}}`
3. Replace it with the user's actual Firebase config object
4. Write the final file to user's specified location
- Default: `chat/index.html`
- Or ask user for preferred path
## Step 3: Provide Setup Instructions
After generating the file:
1. Read and display `resources/setup-guide.md`
2. Remind user about these critical steps:
- Add their domain to Firebase Authorized Domains
- Configure Firestore security rules
- Test with Live Server or deploy to hosting
## Success Message
"""
聊天室已成功建立!
檔案位置:[輸出路徑]
請使用 Live Server 開啟 index.html 進行測試。
如果遇到登入問題,請確認已在 Firebase Console 的
Authentication > Settings > Authorized domains 中
新增您的網域(localhost 通常已預設加入)。
"""
模板的基本 HTML 結構,包含登入和聊天兩個頁面。
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>即時聊天室</title>
<style>
/* 完整 CSS 樣式 - 深色主題 */
</style>
</head>
<body>
<!-- 登入頁面 -->
<div class="login-page" id="loginPage">
<div class="login-card">
<h1>即時聊天室</h1>
<button class="google-btn" id="googleLoginBtn">
使用 Google 帳號登入
</button>
</div>
</div>
<!-- 聊天室頁面 -->
<div class="chat-page" id="chatPage">
<!-- 頂部導航、訊息區域、輸入區域 -->
</div>
</body>
</html>
使用 CSS 變數打造深色主題,訊息氣泡有「自己」和「他人」兩種樣式。
:root {
--primary: #6366f1; /* 主題紫色 */
--bg-dark: #0f172a; /* 深色背景 */
--bg-card: #1e293b; /* 卡片背景 */
--text: #f1f5f9; /* 文字顏色 */
}
/* 訊息氣泡 - 他人 */
.message-content {
background: var(--bg-card);
border-radius: 18px;
border-top-left-radius: 4px; /* 左上角尖角 */
}
/* 訊息氣泡 - 自己 */
.message.own .message-content {
background: linear-gradient(135deg, var(--primary), #4f46e5);
border-top-left-radius: 18px;
border-top-right-radius: 4px; /* 右上角尖角 */
}
/* 響應式設計 */
@media (max-width: 768px) {
.message { max-width: 90%; }
}
Firebase 初始化使用 {{FIREBASE_CONFIG}} 作為替換標記。
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js';
import { getAuth, signInWithPopup, GoogleAuthProvider, onAuthStateChanged }
from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js';
import { getFirestore, collection, addDoc, query, orderBy, onSnapshot }
from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore.js';
// ========================================
// Firebase 配置 - 這裡是替換點!
// ========================================
const firebaseConfig = {{FIREBASE_CONFIG}};
// 初始化
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
// onSnapshot 即時監聽訊息
onSnapshot(query(collection(db, 'messages'), orderBy('timestamp')),
(snapshot) => { /* 更新 UI */ });
// addDoc 發送訊息
await addDoc(collection(db, 'messages'), { text, userId, timestamp });
</script>
提供使用者完成 Firebase 設定的詳細指南。
# Firebase 設定指南
## 1. 開通 Google 登入
- 前往 Firebase Console
- 選擇 Authentication > Sign-in method
- 點擊 Google > 啟用
- 填寫專案公開名稱和支援電子郵件
- 儲存
## 2. 設定授權網域
- Authentication > Settings > Authorized domains
- 預設已有 localhost(本機開發用)
- 部署後需新增你的正式網域
## 3. Firestore 安全規則
將以下規則貼到 Firestore > 規則:
```javascript
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /messages/{messageId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid;
}
}
}
```
## 4. 測試你的聊天室
- 使用 VS Code 的 Live Server 開啟 index.html
- 使用 Google 帳號登入
- 開啟兩個瀏覽器視窗測試即時同步
建立完成後,讓我們來測試這個 Skill 是否正常運作!
.agent/skills/firebase-chat-generator/.claude/skills/firebase-chat-generator/
index.html
編輯你的 Firebase Chat Generator SKILL.md,完成後可一鍵打包下載。
{{FIREBASE_CONFIG}} 位置即可!
恭喜你完成了 Antigravity Skill 的完整培訓!
理解 Skill 是 AI 的 SOP
Skill 讓 AI 照著你設計的流程執行任務
學會 SKILL.md 語法結構
Frontmatter + Markdown 指令的完美組合
親手實作基礎 Skill
從簡單的「打招呼」Skill 開始練習
挑戰 Firebase 自動化建置
結合模板管理,打造專業級 Skill
你已經從「使用 AI」進化到「指揮 AI」!
現在,你是設計流程的架構師,而不只是寫程式碼的工人。
學會了 Skill 的核心概念,接下來挑戰自己吧!
感謝您的學習!