add-section

Create a new HUD section (tab) with lifecycle, persistent state, and registry registration

181 stars

Best use case

add-section is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create a new HUD section (tab) with lifecycle, persistent state, and registry registration

Teams using add-section should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/add-section/SKILL.md --create-dirs "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main/skills/data/add-section/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/add-section/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How add-section Compares

Feature / Agentadd-sectionStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create a new HUD section (tab) with lifecycle, persistent state, and registry registration

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Add Section Skill

## Usage
```
/add-section <SectionName>
```

---

## Step 1: Ask Questions

### 1. Section Purpose
```
Brief description (1 sentence):
What does this section display/manage?
```

### 2. Persistent State
```
What state needs to persist across sessions?
(Must be JSON-serializable: strings, numbers, booleans, arrays, plain objects)

Examples:
- Selected tab/filter
- Sort order
- Collapsed/expanded states
- User preferences
```

### 3. Game Data
```
Does this section need game data?

A) Static data → MGData (plants, items, pets, etc.)
B) Real-time state → Globals (myInventory, myGarden, etc.)
C) Both
D) None
```

### 4. Sprites
```
Does it display game sprites? → MGSprite.toCanvas()
```

### 5. Child Components
```
Does it need existing UI components?
→ REUSE from src/ui/components/

[ ] ArcadeButton, GeminiIconButton → Buttons
[ ] Modal → Dialogs
[ ] ProgressBar → Progress
[ ] SegmentedControl → Tab-like selection
[ ] Tab → Tabs
[ ] SoundPicker → Audio
[ ] Other: ___
```

### 6. Complexity
```
A) Simple - Single file section
B) Complex - Split into parts/ folder
```

### 7. Tab Info
```
- Label (displayed in tab bar): ___________
- Icon (emoji): ___________
```

---

## Step 2: Create Structure

### Simple Section
```
src/ui/sections/<SectionName>/
├── index.ts          # Public exports
├── section.ts        # build() / destroy() lifecycle
├── state.ts          # Persistent state (createSectionStore)
└── styles.css.ts     # Scoped CSS (optional)
```

### Complex Section (with parts)
```
src/ui/sections/<SectionName>/
├── index.ts
├── section.ts        # Assembles parts
├── state.ts
├── styles.css.ts
└── parts/
    ├── header.ts     # Search, filters
    ├── content.ts    # Main content
    └── footer.ts     # Actions
```

**Read existing sections for templates:** `src/ui/sections/*/`

---

## Step 3: File Responsibilities

| File | Purpose |
|------|---------|
| `index.ts` | Export `<Name>Section` and types only |
| `section.ts` | `build(container)`, `destroy()`, `cleanups[]` |
| `state.ts` | `createSectionStore()` with stable ID `tab-<name>` |
| `styles.css.ts` | CSS string with scoped classes |
| `parts/*.ts` | Sub-components with own `destroy()` |

### Key Patterns

#### state.ts
```typescript
import { createSectionStore } from '../core/state';

export interface <Name>State {
    // JSON-serializable only!
    selectedTab: string;
    sortOrder: 'asc' | 'desc';
}

const DEFAULT_STATE: <Name>State = {
    selectedTab: 'all',
    sortOrder: 'asc',
};

// ID must be stable forever (storage key)
export const state = createSectionStore<<Name>State>('tab-<name>', {
    version: 1,  // Increment when state shape changes
    defaults: DEFAULT_STATE,
});
```

#### section.ts
```typescript
export interface SectionDefinition {
    build(container: HTMLElement): void;
    destroy(): void;
}

let root: HTMLElement | null = null;
const cleanups: (() => void)[] = [];

function build(container: HTMLElement): void {
    if (root) return;  // Prevent double-build

    root = document.createElement('div');
    root.className = '<name>-section';

    // Inject styles
    const style = document.createElement('style');
    style.textContent = <name>Css;
    root.appendChild(style);

    // Subscribe to state
    const unsub = state.subscribe((s) => { /* update UI */ });
    cleanups.push(unsub);

    // Add child components (reuse existing!)
    // const button = createArcadeButton({ ... });
    // cleanups.push(() => button.destroy());

    container.appendChild(root);
}

function destroy(): void {
    cleanups.forEach(fn => fn());
    cleanups.length = 0;
    root?.remove();
    root = null;
}

export const <Name>Section: SectionDefinition = { build, destroy };
```

---

## Step 4: Register

### Registry → `src/ui/sections/registry.ts`
```typescript
import { <Name>Section } from './<SectionName>';

export const sectionRegistry: Record<string, SectionConfig> = {
    // ... existing
    'tab-<name>': {
        id: 'tab-<name>',
        label: '<Label>',
        icon: '<emoji>',
        section: <Name>Section,
    },
};
```

---

## Step 5: Validate

### Structure
- [ ] `index.ts` exports `<Name>Section` only
- [ ] `section.ts` has `build()` and `destroy()`
- [ ] `state.ts` uses `createSectionStore()` with stable ID

### State
- [ ] All fields JSON-serializable (no functions, DOM, classes)
- [ ] Section ID is `tab-<name>` format (stable forever)
- [ ] `version` incremented when state shape changes
- [ ] Default state is complete (no undefined)

### Lifecycle
- [ ] `build()` guards against double-build (`if (root) return`)
- [ ] `destroy()` cleans up ALL resources
- [ ] Subscriptions unsubscribed in `destroy()`
- [ ] Child components' `destroy()` called

### Styling
- [ ] Uses CSS variables (no hardcoded colors)
- [ ] Classes scoped (`.section-name__element`)
- [ ] Styles injected into `root`, not `document.head`

### Game Data (if applicable)
- [ ] Static data → `MGData.get()`
- [ ] Real-time → Globals with `.subscribe()` + cleanup
- [ ] Sprites → `MGSprite.toCanvas()`

### Components (if applicable)
- [ ] Reuses existing components from `src/ui/components/`
- [ ] Child components tracked in `cleanups[]`

### Registration
- [ ] Added to `src/ui/sections/registry.ts`
- [ ] ID matches state ID (`tab-<name>`)

---

## Existing Sections

For reference/templates:
- `Settings` - User preferences
- `AutoFavoriteSettings` - Feature config
- `JournalChecker` - Journal progress
- `Pets` - Pet management
- `Trackers` - Stats tracking
- `Alerts` - Notifications config
- `Dev` - Developer tools
- `Test` - Testing section

---

## References

- Rules: `.claude/rules/ui/sections.md`
- Existing sections: `src/ui/sections/*/`
- Core state: `src/ui/sections/core/state.ts`
- UI Components: `src/ui/components/`
- Split workflow: `.claude/workflows/ui/section/split-section-into-parts.md`

Related Skills

chrome-debug

159
from majiayu000/claude-skill-registry

This skill empowers AI agents to debug web applications and inspect browser behavior using the Chrome DevTools Protocol (CDP), offering both collaborative (headful) and automated (headless) modes.

Coding & DevelopmentClaude

ux

159
from majiayu000/claude-skill-registry

This AI agent skill provides comprehensive guidance for creating professional and insightful User Experience (UX) designs, covering user research, information architecture, interaction design, visual guidance, and usability evaluation. It aims to produce actionable, user-centered solutions that avoid generic AI aesthetics.

UX Design & StrategyClaude

vly-money

159
from majiayu000/claude-skill-registry

Generate crypto payment links for supported tokens and networks, manage access to X402 payment-protected content, and provide direct access to the vly.money wallet interface.

Fintech & CryptoClaude

ontopo

159
from majiayu000/claude-skill-registry

An AI agent skill to search for Israeli restaurants, check table availability, view menus, and retrieve booking links via the Ontopo platform, acting as an unofficial interface to its data.

General Utilities

thor-skills

159
from majiayu000/claude-skill-registry

An entry point and router for AI agents to manage various THOR-related cybersecurity tasks, including running scans, analyzing logs, troubleshooting, and maintenance.

SecurityClaude

grail-miner

159
from majiayu000/claude-skill-registry

This skill assists in setting up, managing, and optimizing Grail miners on Bittensor Subnet 81, handling tasks like environment configuration, R2 storage, model checkpoint management, and performance tuning.

DevOps & Infrastructure

lets-go-rss

159
from majiayu000/claude-skill-registry

A lightweight, full-platform RSS subscription manager that aggregates content from YouTube, Vimeo, Behance, Twitter/X, and Chinese platforms like Bilibili, Weibo, and Douyin, featuring deduplication and AI smart classification.

Content & Documentation

modal-deployment

159
from majiayu000/claude-skill-registry

Run Python code in the cloud with serverless containers, GPUs, and autoscaling using Modal. This skill enables agents to generate code for deploying ML models, running batch jobs, serving APIs, and scaling compute-intensive workloads.

DevOps & Infrastructure

astro

159
from majiayu000/claude-skill-registry

This skill provides essential Astro framework patterns, focusing on server-side rendering (SSR), static site generation (SSG), middleware, and TypeScript best practices. It helps AI agents implement secure authentication, manage API routes, and debug rendering behaviors within Astro projects.

Coding & Development

whisper-transcribe

159
from majiayu000/claude-skill-registry

Transcribes audio and video files to text using OpenAI's Whisper CLI, enhanced with contextual grounding from local markdown files for improved accuracy.

Media Processing

tech-blog

159
from majiayu000/claude-skill-registry

Generates comprehensive technical blog posts, offering detailed explanations of system internals, architecture, and implementation, either through source code analysis or document-driven research.

Content & DocumentationClaude

advanced-skill-creator

181
from majiayu000/claude-skill-registry

Meta-skill that generates domain-specific skills using advanced reasoning techniques. PROACTIVELY activate for: (1) Create/build/make skills, (2) Generate expert panels for any domain, (3) Design evaluation frameworks, (4) Create research workflows, (5) Structure complex multi-step processes, (6) Instantiate templates with parameters. Triggers: "create a skill for", "build evaluation for", "design workflow for", "generate expert panel for", "how should I approach [complex task]", "create skill", "new skill for", "skill template", "generate skill"