The Complete Production SOP: How to Deploy and Run Pinia Modular State Stores & Actions with TypeScript in Autonomous AI Agents
Step-by-step SOP to install and run Pinia Modular State Stores with TypeScript in Codex, Claude Code, and Cursor. Master setup stores and reactivity.
Technical Overview & Architectural Context
When autonomous coding agents (Codex, Claude Code, Cursor, Windsurf) are tasked with building state management in Vue 3 applications, they frequently default to outdated Vuex idioms or mix Pinia Options API with Setup Stores unpredictably. Even when modern Pinia syntax is attempted, agents routinely introduce silent reactivity breakage by destructuring reactive state directly inside Vue components without `storeToRefs()`, or by failing to type asynchronous actions with strict return promises. The `pinia-vue-state-management` skill establishes deterministic boundaries for autonomous agents. It forces agents to leverage Pinia Setup Store syntax (`defineStore('id', () => { ... })`), correctly expose refs as state, computed properties as getters, and plain functions as actions. By restricting workspace mutations and defining strict verification gates, this skill ensures type-safe, modular, and leak-free state architectures across enterprise Vue 3 codebases.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the Pinia skill specification into the agent's global or workspace-level skill registry.
Autonomous runtimes like Claude Code, Cursor, and Codex parse procedural instructions from canonical `.agents/skills` directories. Injecting `SKILL.md` ensures the agent intercepts queries related to Pinia store creation, Setup Store syntax, and state persistence.
mkdir -p .agents/skills/pinia-vue-state-management && curl -fsSL https://askills.dev/api/skills/pinia-vue-state-management/raw -o .agents/skills/pinia-vue-state-management/SKILL.md---
name: "pinia-vue-state-management"
description: "Manage global reactive state in Vue 3 applications using official type-safe Pinia stores."
metadata:
author: "Eduardo San Martin Morote"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "create pinia store"
- "setup store syntax pinia"
- "persist pinia state"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Place the skill within `.cursor/rules` or `.agents/skills` at the repository root to ensure all project contributors inherit the same deterministic state architecture without consuming personal context quotas.
Ensure `fs_write` is scoped strictly to the workspace. Do not grant `shell_exec` unless the agent is explicitly required to run test suites or install packages.
Dependency Validation & TypeScript Typecheck Gate
Ensure pinia and optional persistence plugins are installed and validated in package.json.
Before the agent generates stores, verify that `pinia` and required storage plugins (e.g., `pinia-plugin-persistedstate`) are installed. The agent must verify `tsconfig.json` includes proper DOM and ESNext library types for reactivity tracking.
pnpm add pinia pinia-plugin-persistedstate && pnpm add -D @types/node vue-tscimport { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import App from './App.vue'
const app = createApp(App)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(pinia)
app.mount('#app')Instruct the agent to inspect `src/main.ts` prior to creating stores so it verifies that `createPinia()` is instantiated and installed on the Vue instance.
Failing to mount `piniaPluginPersistedstate` into `createPinia()` causes stores configuring `persist: true` to fail silently at runtime.
Intent Matching & Trigger Invocation
Activate the skill deterministically via trigger keywords for modular Setup Store generation.
Invoke the agent using targeted triggers such as `create pinia store` or `setup store syntax pinia`. The agent adheres to the SOP: creating a composable-like store using `defineStore` with explicit TypeScript models, computed getters, and async error-handled actions.
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
export interface UserProfile {
id: string
email: string
roles: string[]
}
export const useAuthStore = defineStore('auth', () => {
const token = ref<string | null>(null)
const user = ref<UserProfile | null>(null)
const isLoading = ref<boolean>(false)
const isAuthenticated = computed<boolean>(() => Boolean(token.value))
const hasAdminRole = computed<boolean>(() => user.value?.roles.includes('admin') ?? false)
async function login(credentials: { email: string; pass: string }): Promise<void> {
isLoading.value = true
try {
const res = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(credentials)
})
if (!res.ok) throw new Error(`Authentication failed with status ${res.status}`)
const data = await res.json()
token.value = data.token
user.value = data.user
} finally {
isLoading.value = false
}
}
function logout(): void {
token.value = null
user.value = null
}
return {
token,
user,
isLoading,
isAuthenticated,
hasAdminRole,
login,
logout
}
}, {
persist: true
})Ensure the agent exports explicit TypeScript interfaces for all complex state objects to prevent inferring `any` in Vue template bindings.
Agents often accidentally destructure store instances in components. The SOP mandates instructing the agent to import `storeToRefs` for non-function store properties.
Verification, Linting & Output Quality Gate
Execute type-checking and component consumption verification before finalizing code.
Instruct the autonomous agent to validate the store by running `vue-tsc --noEmit` and building a consumption component ensuring `storeToRefs()` preserves reactivity.
npx vue-tsc --noEmit && pnpm lint<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { useAuthStore } from '@/stores/useAuthStore'
const authStore = useAuthStore()
// storeToRefs ensures reactivity is retained when destructuring state and getters
const { user, isAuthenticated, hasAdminRole, isLoading } = storeToRefs(authStore)
// Actions are bound functions and can be destructured directly
const { logout } = authStore
</script>
<template>
<section v-if="isAuthenticated">
<p>Welcome, {{ user?.email }}</p>
<span v-if="hasAdminRole">Admin Privileges Active</span>
<button :disabled="isLoading" @click="logout">Sign Out</button>
</section>
</template>Always execute `vue-tsc --noEmit` instead of plain `tsc` to verify that Pinia reactivity and store consumption are valid inside `.vue` Single File Components.
Directly running `const { user } = authStore` will strip reactivity. The agent must strictly use `storeToRefs(authStore)` for refs and getters.
Real-World Scenario: Build a Persisted Multi-Cart Checkout Store in Vue 3 & TypeScript
“create pinia store for shopping cart state management using setup store syntax pinia and persist pinia state across browser reloads. Include actions for add, remove, and calculate total with tax.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to invoke a Pinia store hook (e.g. `useCartStore()`) in a module top-level scope before `app.use(pinia)` completed execution in main.ts.
Move store invocations inside Vue component `<script setup>`, router navigation guards, or wrap within a callback executed after app initialization.Root Cause: Agent destructured properties directly (`const { user } = useAuthStore()`) breaking the ES6 Proxy wrapper, or mixed Options API properties into a Setup Store without returning them.
Wrap store destructuring with `storeToRefs`: `import { storeToRefs } from 'pinia'; const { user } = storeToRefs(authStore);` and verify all refs are returned in the Setup Store function.Frequently Asked Questions (Pinia Modular State Stores & Actions with TypeScript SOP)
Q:Can I use Pinia Modular State Stores & Actions with TypeScript across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. Simply mirror the skill directory into your repository or global agent rules.
Q:How does Pinia Modular State Stores & Actions with TypeScript prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules, the agent immediately knows to use Setup Store syntax without iterative back-and-forth prompts.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes without requiring shell or network access.
Ready to equip your autonomous agent with Pinia Modular State Stores & Actions with TypeScript?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.