home / skills / oimiragieo / agent-studio / class-based-state-management
This skill enforces class based state management in Svelte components to organize complex state machines in .svelte.ts files.
npx playbooks add skill oimiragieo/agent-studio --skill class-based-state-managementReview the files below or copy the command above to add this skill to your agents.
---
name: class-based-state-management
description: Enforces the use of classes for complex state management (state machines) in Svelte components. Applies specifically to `.svelte.ts` files.
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]
globs: '**/*.svelte.ts'
best_practices:
- Follow the guidelines consistently
- Apply rules during code review
- Use as reference when writing new code
error_handling: graceful
streaming: supported
---
# Class Based State Management Skill
<identity>
You are a coding standards expert specializing in class based state management.
You help developers write better code by applying established guidelines and best practices.
</identity>
<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>
<instructions>
When reviewing or writing code, apply these guidelines:
- Use classes for complex state management (state machines):
typescript
// counter.svelte.ts
class Counter {
count = $state(0);
incrementor = $state(1);
increment() {
this.count += this.incrementor;
}
resetCount() {
this.count = 0;
}
resetIncrementor() {
this.incrementor = 1;
}
}
export const counter = new Counter();
</instructions>
<examples>
Example usage:
```
User: "Review this code for class based state management compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>
## Memory Protocol (MANDATORY)
**Before starting:**
```bash
cat .claude/context/memory/learnings.md
```
**After completing:** Record any new patterns or exceptions discovered.
> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
This skill enforces using classes for complex state management and state machines inside Svelte component TypeScript files (.svelte.ts). It ensures stateful logic is encapsulated in class instances to improve testability, reusability, and predictability. The guidance targets patterns like counters, toggles, and multi-step machines implemented as classes and exported for component use.
The skill inspects .svelte.ts files and flags state logic that is not organized into classes when complexity grows beyond trivial reactive stores. It looks for patterns such as multiple related state fields, methods that mutate state, and state machine transitions, recommending a class wrapper with $state-backed fields and methods. It provides concrete refactor suggestions and small code examples to convert ad-hoc state into a class-based design.
Does every piece of state need a class?
No. Small, independent reactive values are fine as stores. Use classes when multiple related values and transition logic form a coherent unit.
How do I test class-based state?
Instantiate the class in unit tests and exercise its public methods, asserting state changes without rendering the component.