explanatory-playground
Scannednpx machina-cli add skill petekp/claude-code-setup/explanatory-playground --openclawExplanatory Playground
Build dev-only visualizations that make invisible system behavior visible.
Workflow
1. Clarify the target
Use AskUserQuestion to understand what needs visualization:
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:
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
| System | Visualization | Library |
|---|---|---|
| State machines | Node-edge graph | react-flow |
| Data flow | Directed graph / Sankey | react-flow |
| Events | Timeline | custom or recharts |
| Algorithms | Step animation | custom |
| Render cycles | Component tree + diffs | custom |
| Animations | Timeline scrubber | custom |
| CSS/Layout | Box model overlay | custom |
See references/patterns.md for layouts, code, and implementation details.
4. Choose interactivity level
Ask if unclear:
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"
| Level | Features | When |
|---|---|---|
| 1 - Observe | Real-time state display | Always |
| 2 - Inspect | Click/hover for details | Usually |
| 3 - Manipulate | Trigger events, modify state | Edge cases |
| 4 - Time travel | History scrubbing, replay | Race conditions |
Start with 1-2. Add 3-4 when needed.
6. Instrument minimally
Prefer event emitters (least invasive):
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:
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
app/__dev/[system-name]/page.tsx
Guard against production:
if (process.env.NODE_ENV !== 'development') {
return notFound();
}
8. Document removal
Header in every created file:
/**
* 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:
- Delete
__dev/route - Remove instrumentation (emitters, proxies)
- Uninstall added deps if unused elsewhere
- Search for
EXPLANATORY-PLAYGROUNDmarkers
Report what was removed.
Source
git clone https://github.com/petekp/claude-code-setup/blob/main/skills/explanatory-playground/SKILL.mdView on GitHub Overview
Explanatory Playground builds dev-only visualizations that reveal invisible system behavior. It helps teams understand complex flows by rendering state, transitions, data shapes, and timing in an interactive UI. Use it to answer how something works, why changes occur, or to debug opaque features.
How This Skill Works
Start by clarifying what system should be revealed (state machines, data flow, event systems, algorithms). Then surface what’s hidden—state values, transitions, relationships, and logic—and map them to a visualization approach (node-edge graphs, timelines, or step animations). Finally instrument the code minimally with an event emitter or a Proxy-based wrapper to feed live data into the playground (e.g., debugEmitter for transitions or a proxy that dispatches state change events).
When to Use It
- You’re asked to explain how a system works or why changes occur
- You need to see what’s happening in real time or how data moves through a pipeline
- You want to visualize the current state, transitions, or data shapes
- You’re building a dedicated debug view for a feature or flow
- You want to surface hidden internals like timing, sequence, or CSS calculations
Quick Start
- Step 1: Clarify the target with questions like 'System type' and 'Hidden aspect' to decide what to visualize
- Step 2: Identify hidden aspects to surface (state, transitions, data shape, timing) and choose a visualization approach
- Step 3: Instrument minimally using an event emitter or a Proxy wrapper to feed visualization data and start a basic debug view
Best Practices
- Clarify the target first: ask what should be visualized and who will use the playground
- Identify what’s hidden: surface state, transitions, relationships, and logic you need to understand
- Choose visualization per system type: state machines -> node-edge graph; data flow -> directed/Sankey; events -> timeline; algorithms -> step animation; render/CSS -> component tree or box-model overlay
- Decide the right interactivity level (observe, inspect, manipulate, time travel) and start simple
- Instrument minimally: prefer event emitters and proxies to minimize intrusion into the codebase
Example Use Cases
- Debug a login state machine by showing the current state and the transitions that lead to success or failure
- Visualize a data pipeline from API -> transform -> render with a directed graph and live data counts
- Trace event propagation in a publish/subscribe system over time with a timeline
- Step through a pathfinding algorithm with a live, animated state timeline and decision points
- Inspect a React render cycle and CSS calculations via a component-tree overlay and layout events