檢查器編輯模式 (以工作階段為範圍)
規則建立有狀態、以工作階段為範圍的檢查器編輯模式,用於共同維護 React 元件及其對應的獨立開發檢查器,避免跨工作階段污染。
登入即可存取這項規則
登入 Google 開發人員個人檔案,即可查看及複製「Build It!」系列中使用的完整規則。
須具備開發人員設定檔
您不符合建立開發人員設定檔的資格。請通知 Workspace 管理員啟用這項功能。
建立開發人員設定檔
免費建立 Google 開發人員個人檔案,即可解鎖所有 Build It! 技能、規則、提示詞和構件。
加入 Builder Central 即可解鎖
一鍵領取免費的 Builder 會員徽章,即可解鎖所有 Build It! 技能、規則、提示和構件。
以工作階段為範圍的檢查器編輯模式運作方式
當您在開啟元件檢查器的情況下疊代 UI 元件時,您會希望元件編輯內容在同一輪中更新相符的檢查器檢視畫面,而不會在日後的工作階段中永久強制執行檢查器編輯內容。這項規則使用對話範圍的標記檔案來解決這個問題:
- 每次新工作階段預設為關閉:全新對話會以一般模式啟動,因此一般編輯只會影響你指定的檔案。
- 進入檢查器編輯模式:說出「進入檢查器編輯模式」(或「開啟檢查器模式」)。代理程式會在
<appDataDir>/brain/<conversation-id>/inspector-mode.active建立以工作階段為範圍的標記檔案、讀取src/dev/registry.ts,並列出這個工作階段涵蓋的所有已註冊元件。 - 自動共同維護:啟用後,您對已註冊元件要求的任何變更都會先更新元件,並立即使用元件檢查工具更新工具工作流程同步處理相符的
src/dev/inspectors/[ComponentName]Inspector.tsx、執行npx tsc --noEmit,並在回覆中加上確認方塊。 - 隨時退出:說出「退出檢查器編輯模式」即可移除標記檔案,返回一般單一目標編輯模式。在某個工作階段開啟此模式,不會影響平行或未來的工作階段。
如何在 Google Antigravity 中安裝
將這項規則放在 Google Antigravity 工作區,並與第 9 集的兩個 Component Inspector 技能並列:
- 在專案工作區中建立
.agents/rules/資料夾 (或依序開啟 Google Antigravity 的「Customizations」>「Rules」,新增工作區規則)。 - 將下列完整 Markdown 規則儲存為
.agents/rules/中的inspector-editing-mode.md。 - 安裝隨附技能「Component Inspector Generator」和「Component Inspector Updater」,讓代理具備這項規則參照的鷹架和同步工作流程。
檢查器編輯模式規則定義
將這項完整的規則定義複製到工作區,並命名為 inspector-editing-mode.md。
inspector-editing-mode.md (.agents/rules/inspector-editing-mode.md)
# Inspector Editing Mode (Session-Scoped)
This rule establishes a stateful, session-scoped **Inspector Editing Mode** for co-maintaining React components and their corresponding isolated development inspectors (`src/dev/inspectors/[ComponentName]Inspector.tsx`).
---
## 1. Scope & Isolation Model
* **Session-Scoped**: The on/off state of this mode is strictly scoped to the current conversation session (`<conversation-id>`).
* **Default State**: Every new conversation session begins with Inspector Editing Mode **OFF** by default.
* **State Marker**:
- Activation is tracked at `<appDataDir>/brain/<conversation-id>/inspector-mode.active`.
- If this file exists for the active session's conversation ID, Inspector Editing Mode is **ON**.
- If this file does NOT exist, Inspector Editing Mode is **OFF**.
* **Zero Cross-Session Contamination**: Turning this mode on in one conversation has no effect on any other parallel or future conversation sessions.
---
## 2. Trigger Commands & State Transitions
### A. Entering Inspector Mode
* **Trigger Phrases**:
- *"Enter inspector editing mode"*
- *"Start inspector editing mode"*
- *"Turn on inspector mode"*
- *"Inspector mode on"*
* **Agent Action**:
1. Create the marker file at `<appDataDir>/brain/<conversation-id>/inspector-mode.active`.
2. Read `src/dev/registry.ts` to identify all currently registered components.
3. Respond confirming:
- Inspector Editing Mode is now **ACTIVE** for this session.
- Any subsequent changes to registered components will automatically update both the component and its dev inspector.
- List the currently registered components covered by this mode.
### B. Exiting Inspector Mode
* **Trigger Phrases**:
- *"Exit inspector editing mode"*
- *"Stop inspector editing mode"*
- *"Turn off inspector mode"*
- *"Inspector mode off"*
* **Agent Action**:
1. Remove the marker file at `<appDataDir>/brain/<conversation-id>/inspector-mode.active` if present.
2. Respond confirming that Inspector Editing Mode is now **DEACTIVATED** for this session and normal single-target editing has resumed.
### C. Status Query
* **Trigger Phrases**:
- *"Is inspector mode active?"*
- *"Inspector mode status"*
- *"What mode am I in?"*
* **Agent Action**:
- Check for the existence of `<appDataDir>/brain/<conversation-id>/inspector-mode.active`.
- Report whether the current session is in **Inspector Mode** or **Normal Mode**.
---
## 3. Co-Maintenance Behavior While Mode is ACTIVE
Whenever the user requests changes, fixes, or refactors to ANY component registered in `src/dev/registry.ts`:
1. **Step 1: Update the Core Component**
- Apply the requested code changes, props modifications, or behavioral logic in `src/components/.../[ComponentName].tsx` (or `src/views/.../[ComponentName].tsx`).
- Update any relevant unit tests in `scripts/` or `__tests__/`.
2. **Step 2: Automatically Synchronize the Dev Inspector**
- Locate the matching inspector at `src/dev/inspectors/[ComponentName]Inspector.tsx`.
- Apply the `component-inspector-updater` workflow:
- **Props & State**: Reconcile any new, altered, or deleted props into the *Editable State* or *Props State* categories.
- **Computed State**: Update derived `useMemo` metrics if underlying rules or formulas changed.
- **Test Verification Cards**: Synchronize the plain-English test fixtures at the bottom of the inspector with the new behavior, updating click handlers so `[Load Test Fixture]` accurately reflects the new state.
- **Preserve Custom Presets**: Keep all existing scenario presets (e.g. week overhauls, superset pairs, edge cases) intact, adapting their shapes to new prop signatures.
- **Advance Timestamp Chip**: Advance `const GENERATED_AT = 'YYYY-MM-DD HH:MM [TIMEZONE]';` to the current local timestamp.
- **No Auto-Scroll**: Ensure all internal scrolling is scoped strictly to element containers (`containerRef.current.scrollTop = containerRef.current.scrollHeight`) with zero page-level scrolling.
3. **Step 3: Verify Types**
- Run `npx tsc --noEmit` to ensure type alignment between the component and its inspector.
- **DO NOT** run raw `npm run build` while a local dev server is active to prevent wiping out `.next/` chunk manifests.
4. **Step 4: Badge Confirmation in Response**
- Include an explicit status chip in your response header or summary:
`[Inspector Mode: Synced <ComponentName> & Dev Inspector]`
---
## 4. Behavior While Mode is INACTIVE (Default)
* When the mode is OFF, the agent performs only the exact requested file modifications.
* Do NOT edit `src/dev/inspectors/` unless the user explicitly requests an inspector update or instructs the agent to create a brand new inspector route.