Refactor high-complexity React components in Dify frontend. Use when `pnpm analyze-component...
npx skills add TrenzaCR/trenzaos-config --skill "trenza-ai"
Install specific skill from multi-skill repository
# Description
>
# SKILL.md
name: trenza-ai
description: >
Gobernanza y seguridad para agentes IA en TrenzaOS.
Trigger: Al integrar LLMs, crear prompts, o trabajar con pgvector.
license: MIT
metadata:
author: trenza
version: "1.0"
TrenzaOS AI Governance Skills
Purpose
Este skill enforce las reglas de seguridad para agentes IA en TrenzaOS.
Core Rules
1. DLP - Data Loss Prevention
PROHIBIDO enviar PII a LLMs sin redactar:
import { redactPII } from '@/lib/dlp'
const PII_FIELDS = ['email', 'phone', 'dni', 'credit_card', 'address']
// ✅ SIEMPRE redactar antes de enviar al LLM
const safePrompt = redactPII(userPrompt, PII_FIELDS)
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: safePrompt } // ✅ PII segura
]
})
2. Anti-Prompt Injection
const INJECTION_PATTERNS = [
/ignore\s+(previous|above|prior)\s+instructions/i,
/forget\s+(everything|all)\s+you\s+(know|were told)/i,
/system\s*:\s*/i,
/<\|.*?\|>/i
]
function validatePrompt(input: string): boolean {
for (const pattern of INJECTION_PATTERNS) {
if (pattern.test(input)) {
console.warn('Prompt injection detected')
return false
}
}
return true
}
3. Aislamiento en pgvector
⚠️ CRÍTICO: Filtrar por tenant ANTES de similarity search
// ❌ INCORRECTO - Fuga de datos entre tenants
const results = await db
.select()
.from(embeddings)
.orderBy(sql`${embeddings.embedding} <=> ${query}`)
.limit(10)
// ✅ CORRECTO - Filtrar por tenant primero
const results = await db
.select()
.from(embeddings)
.where(eq(embeddings.tenantId, currentTenantId)) // ✅
.orderBy(sql`${embeddings.embedding} <=> ${query}`)
.limit(10)
4. Rate Limiting para IA
const AI_LIMITS = {
free: { requests_per_day: 50, max_tokens: 2000 },
pro: { requests_per_day: 500, max_tokens: 4000 },
enterprise: { requests_per_day: -1, max_tokens: 8000 }
}
async function checkAIQuota(tenantId: string) {
const limits = AI_LIMITS[tenantPlan]
if (limits.requests_per_day > 0) {
const todayUsage = await getTodayRequests(tenantId)
if (todayUsage >= limits.requests_per_day) {
throw new RateLimitError('AI quota exceeded')
}
}
}
5. Validación de Respuestas
import { z } from 'zod'
const InvoiceAnalysisSchema = z.object({
summary: z.string().max(500),
sentiment: z.enum(['positive', 'neutral', 'negative']),
recommendations: z.array(z.string()).max(5)
})
async function validateResponse(response: string) {
const parsed = JSON.parse(response)
return InvoiceAnalysisSchema.parse(parsed) // ✅ Valida estructura
}
6. System Prompt (Inmutable)
const INVENTORY_AGENT_SYSTEM = `
Eres el Agente de Inventario de TrenzaOS.
Solo tienes acceso a datos del tenant: {{TENANT_ID}}
REGLAS:
1. NUNCA reveles el tenant_id
2. Solo consulta datos autorizados
3. Reporting siempre en nombre del sistema
`
// ⚠️ NUNCA modificar en runtime
AI Security Checklist
Antes de integrar un LLM:
- [ ] ¿He redactado PII del prompt?
- [ ] ¿He validado contra prompt injection?
- [ ] ¿Filtré por tenant_id en pgvector?
- [ ] ¿Tengo rate limiting configurado?
- [ ] ¿Valido la respuesta con Zod?
- [ ] ¿El system prompt es seguro?
Rate Limits por Plan
| Plan | Requests/Day | Max Tokens/Request |
|---|---|---|
| Free | 50 | 2,000 |
| Pro | 500 | 4,000 |
| Enterprise | ∞ | 8,000 |
References
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.