Use when adding new error messages to React, or seeing "unknown error code" warnings.
0
0
# Install this skill:
npx skills add shuiyuan1223/skillfix_xuetang --skill "coding-standards"
Install specific skill from multi-skill repository
# Description
Use when writing or reviewing code for the PHA project. Covers coding conventions, architecture rules, and common patterns.
# SKILL.md
name: coding-standards
description: Use when writing or reviewing code for the PHA project. Covers coding conventions, architecture rules, and common patterns.
PHA Coding Standards
Iron Rules (MUST follow)
AgentOS ๅฒๅญฆ
- Frontend = Pure Renderer โ
ui/src/only renders A2UI JSON. No business logic, no API calls, no data processing. - UI = Agent Output โ All pages generated in
src/gateway/pages.tsviaA2UIGenerator, not frontend. - MCP is the only tool API โ Tools exposed via MCP protocol in
src/tools/. Agent never calls internal functions directly. - Tools = MCP, Knowledge = Skills โ Data operations โ MCP Tool; Expert knowledge โ Skill (
src/skills/*/SKILL.md). Never use bare JSON config files as Skills.
็ๆๅผ UI ็บฆๆ
- A2UI is the only UI protocol โ 4 Surfaces:
main,sidebar,modal,toast. Each is a component tree{ components[], root_id }. - Use A2UIGenerator โ
const ui = new A2UIGenerator("main")โ compose โui.build(rootId). Never hand-write JSON component trees. - No Emoji Icons โ Use icon names (
"heart","brain") iniconproperties, never emoji ("โค๏ธ"). - i18n Sync โ Every user-facing string uses
t(). Changes require updatingtypes.ts+zh-CN.ts+en.tssimultaneously. - Dual Frontend Sync โ Web (React
A2UIRenderer.tsx) and TUI (tui-renderer.ts) consume same A2UI data. New component types need renderers in both. - Tool Display Names โ New MCP tools must be added to
TOOL_DISPLAY_NAMESinui/src/components/a2ui/A2UIRenderer.tsxfor Chinese display names.
้ไฟกๅ่ฎฎ็บฆๆ
- Dual Channel โ Chat messages via SSE (
POST /api/ag-ui), everything else via WebSocket (/ws). SSE sends AG-UI events (RunStarted/TextMessageContent/ToolCallStartetc.), WebSocket sends A2UI page updates. - State Ownership โ Server (
GatewaySession) is the single source of truth for chat history. Frontend maintains local chat state for SSE real-time rendering, but rebuilds from server A2UI on page refresh. Non-chat UI state is fully server-driven. - Action Pattern โ User interactions:
{ type: "action", action: "handler_name", payload: {...} }. Action strings must matchhandleAction()inserver.tsexactly. - Navigate Pattern โ Sidebar clicks:
{ type: "navigate", view: "view_id" }. View IDs must matchhandleNavigate()cases exactly.
ๅทฅ็จ็บชๅพ
- Keep it Simple โ No premature abstractions. No over-engineering. Three similar lines > one premature abstraction.
TypeScript Conventions
- Runtime: Bun
- Build:
tsc --outDir dist(backend) +vite build(frontend) - Imports: Use
.jsextension for local imports (ESM) - Type imports: Use
import typewhere possible - No
any: Except inAgentTool<any>[]array (variance workaround) - Formatting: Prettier (auto via lint-staged)
- Linting: ESLint (auto via lint-staged)
File Organization
| What | Where |
|---|---|
| CLI commands | src/commands/xxx.ts |
| MCP tool definitions | src/tools/xxx-tools.ts |
| Git MCP tools | src/tools/git-tools.ts |
| AgentTool adapters | src/agent/tools.ts, src/agent/git-agent-tools.ts |
| A2UI page generators | src/gateway/pages.ts, src/gateway/evolution-lab.ts |
| Route/action handlers | src/gateway/server.ts |
| A2UI component types | src/gateway/a2ui.ts |
| Evolution system | src/evolution/*.ts |
| Agent Skills | src/skills/*/SKILL.md |
| Memory system | src/memory/*.ts |
| Translations | src/locales/{types,zh-CN,en}.ts |
| Frontend renderer | ui/src/components/a2ui/A2UIRenderer.tsx |
| Frontend icons | ui/src/lib/icons.tsx |
| Tests | tests/unit/, tests/integration/ |
| Test fixtures | tests/fixtures/ |
Common Patterns
Singleton Services
import { getMemoryManager } from "../memory/index.js";
import { getDataSource } from "../tools/health-data.js";
import { getUserUuid } from "../utils/config.js";
Git Operations
- All git operations should go through
src/evolution/version-manager.tsorsrc/tools/git-tools.ts - Use
gitCommitFiles(files, message)for commits, not rawexecSync("git add && git commit") - Import from
"../evolution/version-manager.js"forgitCommitFiles,getProjectRoot, etc.
Error Handling
- Tools: Return
{ success: false, error: message }, never throw - Server: try/catch with
console.error, send error to client - Profile extraction: Best-effort, wrap in try/catch and ignore failures
Session State in GatewaySession
- Add private fields to
GatewaySessionclass for page-specific state - Reset state when navigating away
- Pattern:
this.xxxFieldfor state, read inhandleNavigate, write inhandleAction - SSE mode flags:
_sseMode(chat active via SSE),_chatLock(prevents concurrent chat requests)
SSE Chat Flow
Frontend POST /api/ag-ui โ GatewaySession.handleChatSSE()
โ Agent processes message
โ SSE events stream back: RunStarted โ TextMessageContent* โ ToolCallStart/End โ RunFinished
โ Frontend updates local chat state in real-time
Commit Convention
feat: ๆฐๅ่ฝ
fix: ไฟฎๅค
refactor: ้ๆ
docs: ๆๆกฃ
chore: ๆ้กน
Pre-commit Checklist
bun run check # TypeScript types
bun run lint # ESLint
bun run format:check # Prettier
bun test # Tests
bun run build # Full build
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Amp
Antigravity
Claude Code
Clawdbot
Codex
Cursor
Droid
Gemini CLI
GitHub Copilot
Goose
Kilo Code
Kiro CLI
OpenCode
Roo Code
Trae
Windsurf
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.