AgentSkillsCN

explanatory-playground

构建交互式调试界面,直观呈现系统内部运行机制。当用户提出“帮我理解这是如何运作的”、“给我看看发生了什么”、“可视化当前状态”、“构建调试视图”、“我看不出到底怎么回事”等需求时,或任何希望让晦涩难懂的系统行为变得清晰可见的请求时,均可使用此技能。适用于状态机、数据流、事件系统、算法、渲染周期、动画、CSS计算,以及任何隐藏内部逻辑的机制。

SKILL.md
--- frontmatter
name: explanatory-playground
description: Build interactive debugging interfaces that reveal internal system behavior. Use when asked to "help me understand how this works", "show me what's happening", "visualize the state", "build a debug view", "I can't see what's going on", or any request to make opaque system behavior visible. Applies to state machines, data flow, event systems, algorithms, render cycles, animations, CSS calculations, or any mechanism with hidden internals.

Explanatory Playground

Build dev-only visualizations that make invisible system behavior visible.

Workflow

1. Clarify the target

Use AskUserQuestion to understand what needs visualization:

code
question: "What kind of system should the playground reveal?"
header: "System type"
options:
  - label: "State machine"
    description: "Finite states with transitions (auth flow, form wizard, game state)"
  - label: "Data flow"
    description: "Data transforming through a pipeline (API → transform → render)"
  - label: "Event system"
    description: "Publishers and subscribers, event propagation"
  - label: "Algorithm"
    description: "Step-by-step logic (sorting, pathfinding, search)"

Then ask what's confusing:

code
question: "What specifically is hard to understand?"
header: "Hidden aspect"
options:
  - label: "Current state"
    description: "I can't see what state the system is in right now"
  - label: "Why transitions happen"
    description: "I don't know what triggers changes or why"
  - label: "Data shape"
    description: "I can't see what the data looks like at each step"
  - label: "Timing/sequence"
    description: "Things happen too fast or in unclear order"

2. Identify what's hidden

Based on answers, determine what to surface:

  • State — Values that change over time
  • Transitions — Events that trigger changes
  • Relationships — How parts communicate
  • Logic — Conditions, thresholds, rules

3. Pick visualization approach

SystemVisualizationLibrary
State machinesNode-edge graphreact-flow
Data flowDirected graph / Sankeyreact-flow
EventsTimelinecustom or recharts
AlgorithmsStep animationcustom
Render cyclesComponent tree + diffscustom
AnimationsTimeline scrubbercustom
CSS/LayoutBox model overlaycustom

See references/patterns.md for layouts, code, and implementation details.

4. Choose interactivity level

Ask if unclear:

code
question: "How interactive should the playground be?"
header: "Interactivity"
options:
  - label: "Just show me (Recommended)"
    description: "Real-time display of state and changes"
  - label: "Let me poke around"
    description: "Click/hover to inspect details and trace origins"
  - label: "Let me trigger things"
    description: "Fire events, modify state, inject test data"
  - label: "Time travel"
    description: "Record history, scrub through past states, replay"
LevelFeaturesWhen
1 - ObserveReal-time state displayAlways
2 - InspectClick/hover for detailsUsually
3 - ManipulateTrigger events, modify stateEdge cases
4 - Time travelHistory scrubbing, replayRace conditions

Start with 1-2. Add 3-4 when needed.

6. Instrument minimally

Prefer event emitters (least invasive):

typescript
const debugEmitter = new EventEmitter();
function transition(from, to, event) {
  debugEmitter.emit('transition', { from, to, event, timestamp: Date.now() });
  // existing logic...
}

Use proxies for third-party code:

typescript
function observable<T extends object>(obj: T) {
  return new Proxy(obj, {
    set(target, prop, value) {
      window.dispatchEvent(new CustomEvent('state:change', {
        detail: { prop, old: target[prop], new: value }
      }));
      return Reflect.set(target, prop, value);
    }
  });
}

7. Create dev-only route

code
app/__dev/[system-name]/page.tsx

Guard against production:

typescript
if (process.env.NODE_ENV !== 'development') {
  return notFound();
}

8. Document removal

Header in every created file:

typescript
/**
 * EXPLANATORY-PLAYGROUND DEBUG TOOL
 * Remove when done:
 * 1. Delete: app/__dev/[name]/page.tsx
 * 2. Delete: src/lib/[system]-debug.ts
 * 3. Remove hooks from: src/lib/[system].ts (lines XX-YY)
 * Purpose: [what this debugs]
 */

Cleanup

On removal request:

  1. Delete __dev/ route
  2. Remove instrumentation (emitters, proxies)
  3. Uninstall added deps if unused elsewhere
  4. Search for EXPLANATORY-PLAYGROUND markers

Report what was removed.