@luanpdd/kit-mcp 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +86 -0
- package/README.md +58 -0
- package/gates/ai-prompt-stability.md +120 -0
- package/gates/golden-signals-coverage.md +133 -0
- package/gates/legacy-refactor-safety.md +178 -0
- package/gates/observability-coverage.md +151 -0
- package/gates/postmortem-template-required.md +127 -0
- package/gates/prr-checklist-coverage.md +128 -0
- package/gates/release-pipeline-policy.md +132 -0
- package/kit/COMANDOS.md +15 -0
- package/kit/agents/ai-mutation-tester.md +298 -0
- package/kit/agents/cascading-failures-auditor.md +306 -0
- package/kit/agents/executor.md +13 -0
- package/kit/agents/golden-signals-instrumenter.md +241 -0
- package/kit/agents/legacy-characterizer.md +378 -0
- package/kit/agents/load-shedding-instrumenter.md +297 -0
- package/kit/agents/observability-coverage-auditor.md +325 -0
- package/kit/agents/omm-auditor.md +99 -0
- package/kit/agents/payload-capture-instrumenter.md +283 -0
- package/kit/agents/planner.md +29 -0
- package/kit/agents/postmortem-writer.md +282 -0
- package/kit/agents/prr-conductor.md +296 -0
- package/kit/agents/refactor-safety-auditor.md +414 -0
- package/kit/agents/release-pipeline-auditor.md +360 -0
- package/kit/agents/seam-finder.md +367 -0
- package/kit/agents/shotgun-surgery-detector.md +359 -0
- package/kit/agents/storytelling-analyst.md +309 -0
- package/kit/agents/supabase-architect.md +49 -0
- package/kit/agents/supabase-edge-fn-writer.md +114 -0
- package/kit/agents/supabase-migration-writer.md +80 -0
- package/kit/agents/supabase-storage-implementer.md +156 -0
- package/kit/agents/toil-auditor.md +277 -0
- package/kit/agents/verifier.md +30 -0
- package/kit/commands/auditar-cascading.md +111 -0
- package/kit/commands/auditar-marco.md +124 -1
- package/kit/commands/auditar-observabilidade-cobertura.md +183 -0
- package/kit/commands/auditar-refactor.md +219 -0
- package/kit/commands/auditar-release.md +109 -0
- package/kit/commands/auditar-toil.md +129 -0
- package/kit/commands/capturar-payloads.md +193 -0
- package/kit/commands/caracterizar-prompt.md +195 -0
- package/kit/commands/caracterizar.md +212 -0
- package/kit/commands/concluir-marco.md +95 -1
- package/kit/commands/detectar-duplicacao.md +197 -0
- package/kit/commands/discutir-fase.md +41 -0
- package/kit/commands/encontrar-seams.md +136 -0
- package/kit/commands/forense.md +103 -1
- package/kit/commands/golden-signals.md +142 -0
- package/kit/commands/legacy.md +263 -0
- package/kit/commands/load-shedding.md +117 -0
- package/kit/commands/observabilidade.md +2 -0
- package/kit/commands/postmortem.md +179 -0
- package/kit/commands/prr.md +205 -0
- package/kit/commands/refactor-seguro.md +321 -0
- package/kit/commands/risk-budget.md +220 -0
- package/kit/commands/sre.md +230 -0
- package/kit/commands/storytelling.md +179 -0
- package/kit/skills/_shared-legacy/glossary.md +389 -0
- package/kit/skills/_shared-sre/glossary.md +712 -0
- package/kit/skills/ai-prompt-characterization/SKILL.md +335 -0
- package/kit/skills/blameless-postmortems/SKILL.md +340 -0
- package/kit/skills/cascading-failures/SKILL.md +307 -0
- package/kit/skills/eliminating-toil/SKILL.md +243 -0
- package/kit/skills/event-based-slos/SKILL.md +22 -0
- package/kit/skills/four-golden-signals/SKILL.md +314 -0
- package/kit/skills/hermetic-builds/SKILL.md +323 -0
- package/kit/skills/legacy-api-only-applications/SKILL.md +358 -0
- package/kit/skills/legacy-characterization-tests/SKILL.md +330 -0
- package/kit/skills/legacy-effect-analysis/SKILL.md +331 -0
- package/kit/skills/legacy-extract-class/SKILL.md +203 -0
- package/kit/skills/legacy-monster-methods/SKILL.md +444 -0
- package/kit/skills/legacy-programming-by-difference/SKILL.md +252 -0
- package/kit/skills/legacy-seams-and-test-harness/SKILL.md +460 -0
- package/kit/skills/legacy-shotgun-surgery/SKILL.md +286 -0
- package/kit/skills/legacy-sprout-wrap-techniques/SKILL.md +434 -0
- package/kit/skills/legacy-storytelling-naked-crc/SKILL.md +270 -0
- package/kit/skills/llm-as-dependency/SKILL.md +436 -0
- package/kit/skills/load-shedding-graceful-degradation/SKILL.md +396 -0
- package/kit/skills/pre-refactor-characterization/SKILL.md +421 -0
- package/kit/skills/production-readiness-review/SKILL.md +305 -0
- package/kit/skills/release-engineering/SKILL.md +367 -0
- package/kit/skills/retry-strategies/SKILL.md +372 -0
- package/kit/skills/sre-risk-management/SKILL.md +221 -0
- package/package.json +2 -2
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: capturar-payloads
|
|
3
|
+
description: Invoca payload-capture-instrumenter — instrumenta Edge Function Supabase para captura via mcp__supabase__get_logs por N dias, sanitiza PII, gera fixtures para legacy-characterizer. Modernização 2026.
|
|
4
|
+
argument-hint: "<edge_function_path> [--days N] [--max-payloads N] [--mode instrument|drain|full] [--sanitize-keys k1,k2,...]"
|
|
5
|
+
allowed-tools:
|
|
6
|
+
- Read
|
|
7
|
+
- Write
|
|
8
|
+
- Edit
|
|
9
|
+
- Bash
|
|
10
|
+
- Grep
|
|
11
|
+
- Glob
|
|
12
|
+
- Task
|
|
13
|
+
- mcp__supabase__execute_sql
|
|
14
|
+
- mcp__supabase__get_logs
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<objective>
|
|
18
|
+
Instrumentar Edge Function Supabase para capturar **payloads reais** de produção, drenar logs após janela de captura via `mcp__supabase__get_logs`, sanitizar PII deterministicamente, e gerar fixtures prontos para alimentar `/caracterizar`. Invoca o agente [`payload-capture-instrumenter`](../agents/payload-capture-instrumenter.md) que aplica a skill [`legacy-characterization-tests`](../skills/legacy-characterization-tests/SKILL.md) Pattern 7.
|
|
19
|
+
|
|
20
|
+
**Cria/Atualiza:**
|
|
21
|
+
- Patch na Edge Function adicionando log dedicado controlado por env `CAPTURE_PAYLOADS=true`
|
|
22
|
+
- `supabase/functions/_shared/payload-capture.ts` — sanitização canônica
|
|
23
|
+
- `tests/characterization/<edge-fn>/fixtures/payload-NN.json` — fixtures sanitizados após drenagem
|
|
24
|
+
|
|
25
|
+
**Após:** o user tem fixtures BASEADOS EM DISTRIBUIÇÃO REAL de produção, não em sintéticos. Cobertura comportamental cresce significativamente.
|
|
26
|
+
</objective>
|
|
27
|
+
|
|
28
|
+
<context>
|
|
29
|
+
**Argumentos:**
|
|
30
|
+
- `<edge_function_path>` — path da Edge Function (e.g., `supabase/functions/process-orders/index.ts`) — OBRIGATÓRIO
|
|
31
|
+
- `--days N` — janela de captura em dias (default: 7)
|
|
32
|
+
- `--max-payloads N` — máximo de fixtures a salvar (default: 100)
|
|
33
|
+
- `--mode instrument|drain|full` — fase do workflow:
|
|
34
|
+
- `instrument` — só aplica patch (você faz deploy + aguarda)
|
|
35
|
+
- `drain` — só drena logs (após capture já rodou em prod)
|
|
36
|
+
- `full` — patch + aguarda + drena (default — orquestra tudo)
|
|
37
|
+
- `--sanitize-keys k1,k2,k3` — keys adicionais a redact
|
|
38
|
+
|
|
39
|
+
**Workflow esperado:**
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
Dia 0: /capturar-payloads <fn> --mode=instrument
|
|
43
|
+
Dia 0: Você faz deploy + setar CAPTURE_PAYLOADS=true em env
|
|
44
|
+
Dia 1-7: produção captura naturalmente
|
|
45
|
+
Dia 7: /capturar-payloads <fn> --mode=drain
|
|
46
|
+
Dia 7: Fixtures criados em tests/characterization/<fn>/fixtures/
|
|
47
|
+
Dia 7: /caracterizar <fn> --fixtures-dir tests/characterization/<fn>/fixtures
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Exemplos:**
|
|
51
|
+
```
|
|
52
|
+
/capturar-payloads supabase/functions/webhook-stripe/index.ts # full mode 7 dias
|
|
53
|
+
/capturar-payloads supabase/functions/process-orders/index.ts --days 14 # janela maior
|
|
54
|
+
/capturar-payloads supabase/functions/process-orders/index.ts --mode=instrument # só patch
|
|
55
|
+
/capturar-payloads supabase/functions/process-orders/index.ts --mode=drain # só drenagem
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Pré-requisitos:**
|
|
59
|
+
- Edge Function deployada em Supabase (modo drain depende de logs em prod)
|
|
60
|
+
- MCP Supabase conectado para drenagem automatizada (alternativa: `supabase functions logs` CLI)
|
|
61
|
+
- Tier full em IDEs com MCP; tier partial degrada para instrumentação only
|
|
62
|
+
|
|
63
|
+
**Quando preferir este comando vs `/caracterizar` direto:**
|
|
64
|
+
- Edge Function tem alto traffic (≥ 100 req/dia) — distribuição real cobre edge cases que sintético não pega
|
|
65
|
+
- Edge Function tem contrato externo crítico (webhook de Stripe/GitHub) — fidelidade absoluta requer payloads reais
|
|
66
|
+
- Equipe quer baseline empírico antes de refactor — payloads reais > inputs sintéticos
|
|
67
|
+
</context>
|
|
68
|
+
|
|
69
|
+
<process>
|
|
70
|
+
|
|
71
|
+
## 1. Parsear argumentos
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
EDGE_FN_PATH=$(echo "$ARGUMENTS" | awk '{print $1}')
|
|
75
|
+
CAPTURE_DAYS=$(echo "$ARGUMENTS" | grep -oE -- '--days [0-9]+' | awk '{print $2}')
|
|
76
|
+
MAX_PAYLOADS=$(echo "$ARGUMENTS" | grep -oE -- '--max-payloads [0-9]+' | awk '{print $2}')
|
|
77
|
+
MODE=$(echo "$ARGUMENTS" | grep -oE -- '--mode[= ][^ ]+' | sed 's/--mode[= ]//')
|
|
78
|
+
SANITIZE_KEYS=$(echo "$ARGUMENTS" | grep -oE -- '--sanitize-keys [^ ]+' | awk '{print $2}')
|
|
79
|
+
|
|
80
|
+
[ -z "$CAPTURE_DAYS" ] && CAPTURE_DAYS=7
|
|
81
|
+
[ -z "$MAX_PAYLOADS" ] && MAX_PAYLOADS=100
|
|
82
|
+
[ -z "$MODE" ] && MODE="full"
|
|
83
|
+
|
|
84
|
+
if [ -z "$EDGE_FN_PATH" ]; then
|
|
85
|
+
echo "ERROR: edge_function_path obrigatório"
|
|
86
|
+
echo "Uso: /capturar-payloads <path> [opções]"
|
|
87
|
+
exit 1
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
if [ ! -f "$EDGE_FN_PATH" ]; then
|
|
91
|
+
echo "ERROR: arquivo não encontrado: $EDGE_FN_PATH"
|
|
92
|
+
exit 1
|
|
93
|
+
fi
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 2. Validar pré-requisitos
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# verificar Edge Function (Deno + Deno.serve)
|
|
100
|
+
if ! grep -q "Deno.serve" "$EDGE_FN_PATH"; then
|
|
101
|
+
echo "ERROR: $EDGE_FN_PATH não parece Edge Function (sem Deno.serve)"
|
|
102
|
+
exit 1
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
# detectar projeto Supabase
|
|
106
|
+
PROJECT_ID=""
|
|
107
|
+
if [ -f "supabase/config.toml" ]; then
|
|
108
|
+
PROJECT_ID=$(grep -E '^project_id\s*=' supabase/config.toml | sed 's/.*= *"\(.*\)".*/\1/' | head -1)
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
if [ -z "$PROJECT_ID" ] && [ "$MODE" != "instrument" ]; then
|
|
112
|
+
echo "WARN: PROJECT_ID não detectado em supabase/config.toml — drenagem pode falhar"
|
|
113
|
+
fi
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## 3. Dispatch para `payload-capture-instrumenter`
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
Task(
|
|
120
|
+
subagent_type="payload-capture-instrumenter",
|
|
121
|
+
prompt="
|
|
122
|
+
edge_function_path: ${EDGE_FN_PATH}
|
|
123
|
+
capture_days: ${CAPTURE_DAYS}
|
|
124
|
+
max_payloads: ${MAX_PAYLOADS}
|
|
125
|
+
mode: ${MODE}
|
|
126
|
+
${SANITIZE_KEYS:+sanitize_keys: ${SANITIZE_KEYS}}
|
|
127
|
+
${PROJECT_ID:+project_id: ${PROJECT_ID}}
|
|
128
|
+
|
|
129
|
+
Aplicar skill legacy-characterization-tests Pattern 7. Etapas:
|
|
130
|
+
1. Preflight: validar Edge Function, detectar project_id
|
|
131
|
+
2. (mode=instrument|full) Patch Edge Function adicionando log dedicado
|
|
132
|
+
3. (mode=instrument) Output mensagem para fazer deploy + setar CAPTURE_PAYLOADS=true
|
|
133
|
+
4. (mode=drain|full após delay) Drenar logs via mcp__supabase__get_logs
|
|
134
|
+
5. Para cada log entry com kind=payload-capture:
|
|
135
|
+
- Parse payload sanitized
|
|
136
|
+
- Salvar em tests/characterization/<fn>/fixtures/payload-NN.json
|
|
137
|
+
6. Pós-processamento: validar nenhum unredacted, sanitização adicional
|
|
138
|
+
7. Output curto + recomendações (review fixtures, /caracterizar, remove flag)
|
|
139
|
+
"
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 4. Pós-output
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
═══════════════════════════════════════════════════════════
|
|
147
|
+
framework ► CAPTURAR-PAYLOADS ▸ ${EDGE_FN_PATH}
|
|
148
|
+
═══════════════════════════════════════════════════════════
|
|
149
|
+
|
|
150
|
+
[output do payload-capture-instrumenter]
|
|
151
|
+
|
|
152
|
+
## Próximos passos por mode
|
|
153
|
+
|
|
154
|
+
### Após mode=instrument
|
|
155
|
+
1. Deploy: `supabase functions deploy <name>`
|
|
156
|
+
2. Setar env var: `supabase secrets set CAPTURE_PAYLOADS=true`
|
|
157
|
+
3. Aguardar ${CAPTURE_DAYS} dias
|
|
158
|
+
4. Rodar: `/capturar-payloads ${EDGE_FN_PATH} --mode=drain`
|
|
159
|
+
|
|
160
|
+
### Após mode=drain ou full
|
|
161
|
+
1. **REVISAR fixtures** manualmente — sample 5-10 arquivos
|
|
162
|
+
2. **VALIDAR no PII vaza:**
|
|
163
|
+
```bash
|
|
164
|
+
grep -E "([0-9]{3}\.[0-9]{3}\.[0-9]{3}-?[0-9]{2}|@.*\..*\.com)" tests/characterization/*/fixtures/*.json
|
|
165
|
+
```
|
|
166
|
+
3. **Alimentar legacy-characterizer:**
|
|
167
|
+
```bash
|
|
168
|
+
/caracterizar ${EDGE_FN_PATH} --fixtures-dir tests/characterization/$(basename $(dirname ${EDGE_FN_PATH}))/fixtures
|
|
169
|
+
```
|
|
170
|
+
4. **Após characterization gerada:** REMOVE flag CAPTURE_PAYLOADS:
|
|
171
|
+
```bash
|
|
172
|
+
supabase secrets unset CAPTURE_PAYLOADS
|
|
173
|
+
git revert <commit-instrument>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Cross-suite
|
|
177
|
+
|
|
178
|
+
- **/caracterizar** (v1.12) — consome fixtures gerados aqui
|
|
179
|
+
- **/instrumentar-fase** (v1.9) — captura é instrumentação shift-left aplicada
|
|
180
|
+
- **/golden-signals** (v1.10) — captura E golden signals podem coexistir mesma Edge Function
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
</process>
|
|
184
|
+
|
|
185
|
+
<success_criteria>
|
|
186
|
+
- [ ] $ARGUMENTS parseados (edge_function_path obrigatório, 4 flags opcionais)
|
|
187
|
+
- [ ] Pré-requisitos validados (Deno.serve presente; supabase/config.toml para project_id)
|
|
188
|
+
- [ ] `payload-capture-instrumenter` invocado via Task com mode resolvido
|
|
189
|
+
- [ ] Tier degradation correto (Full = MCP drain; Partial = instrument-only)
|
|
190
|
+
- [ ] Output forwarded transparentemente
|
|
191
|
+
- [ ] Próximos passos específicos por mode (instrument vs drain vs full)
|
|
192
|
+
- [ ] Cross-references com /caracterizar, /instrumentar-fase, /golden-signals
|
|
193
|
+
</success_criteria>
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: caracterizar-prompt
|
|
3
|
+
description: Characterization de prompts/tools LLM em produção — temperature=0 + seed fixo + sanitização específica. Trata prompts como código legacy. Modernização 2026 sem precedente em 2004.
|
|
4
|
+
argument-hint: "<prompt_file> [--inputs-dir PATH] [--provider openai|anthropic] [--seed N] [--max-tokens N] [--num-intents N]"
|
|
5
|
+
allowed-tools:
|
|
6
|
+
- Read
|
|
7
|
+
- Write
|
|
8
|
+
- Edit
|
|
9
|
+
- Bash
|
|
10
|
+
- Grep
|
|
11
|
+
- Glob
|
|
12
|
+
- Task
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<objective>
|
|
16
|
+
Caracterizar **prompt LLM ou tool definition** capturando outputs determinísticos como golden snapshots. Aplica skill [`ai-prompt-characterization`](../skills/ai-prompt-characterization/SKILL.md) — `temperature=0`, `seed` fixo, sanitização de timestamps/UUIDs/datas relativas, 5+ intents distintas. Trata prompt como **código legacy também** — versionado, testado, code-reviewed.
|
|
17
|
+
|
|
18
|
+
**Cria/Atualiza:**
|
|
19
|
+
- `tests/characterization/prompts/<prompt-stem>.test.ts` (ou `.py`/`.go` conforme runtime)
|
|
20
|
+
- `tests/characterization/prompts/__snapshots__/<prompt-stem>.test.ts.snap`
|
|
21
|
+
- `tests/characterization/prompts/<prompt-stem>/inputs/<intent>.json` — inputs canônicos por intent
|
|
22
|
+
|
|
23
|
+
**Após:** mudança em prompt deve manter snapshot diff = 0 (ou mudança documentada). Detecta drift de model upstream automaticamente.
|
|
24
|
+
</objective>
|
|
25
|
+
|
|
26
|
+
<context>
|
|
27
|
+
**Argumentos:**
|
|
28
|
+
- `<prompt_file>` — arquivo do prompt (e.g., `prompts/generate-summary.md`) — OBRIGATÓRIO
|
|
29
|
+
- `--inputs-dir <path>` — diretório com inputs canônicos por intent (default: agent gera 5 sintéticos cobrindo concise/detailed/code/edge/adversarial)
|
|
30
|
+
- `--provider openai|anthropic` — provider de LLM (default: detecta via deps)
|
|
31
|
+
- `--seed N` — seed para determinismo (default: 42)
|
|
32
|
+
- `--max-tokens N` — limite output (default: 500)
|
|
33
|
+
- `--num-intents N` — número de intents a cobrir (default: 5; mínimo: 5)
|
|
34
|
+
- `--system-prompt <text>` — system prompt se aplicável
|
|
35
|
+
|
|
36
|
+
**Exemplos:**
|
|
37
|
+
```
|
|
38
|
+
/caracterizar-prompt prompts/generate-summary.md
|
|
39
|
+
/caracterizar-prompt prompts/code-reviewer.md --num-intents 7 --max-tokens 1000
|
|
40
|
+
/caracterizar-prompt prompts/intent-classifier.md --inputs-dir test-data/classifier-intents
|
|
41
|
+
/caracterizar-prompt prompts/customer-support.md --provider anthropic --seed 123
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Pré-requisitos:**
|
|
45
|
+
- ANTHROPIC_API_KEY ou OPENAI_API_KEY em env
|
|
46
|
+
- Test framework (Vitest, Jest, pytest, ...)
|
|
47
|
+
- Provider escolhido suporta `temperature=0` + `seed`
|
|
48
|
+
|
|
49
|
+
**Quando este comando é o caminho:**
|
|
50
|
+
- Prompt em produção > 50 linhas
|
|
51
|
+
- Mudanças em prompt quebraram silenciosamente no passado
|
|
52
|
+
- Equipe quer baseline antes de refactor de prompt
|
|
53
|
+
- CI deve detectar drift de model upstream (Claude 4.7 → 4.8)
|
|
54
|
+
</context>
|
|
55
|
+
|
|
56
|
+
<process>
|
|
57
|
+
|
|
58
|
+
## 1. Parsear argumentos
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
PROMPT_FILE=$(echo "$ARGUMENTS" | awk '{print $1}')
|
|
62
|
+
INPUTS_DIR=$(echo "$ARGUMENTS" | grep -oE -- '--inputs-dir [^ ]+' | awk '{print $2}')
|
|
63
|
+
PROVIDER=$(echo "$ARGUMENTS" | grep -oE -- '--provider [^ ]+' | awk '{print $2}')
|
|
64
|
+
SEED=$(echo "$ARGUMENTS" | grep -oE -- '--seed [0-9]+' | awk '{print $2}')
|
|
65
|
+
MAX_TOKENS=$(echo "$ARGUMENTS" | grep -oE -- '--max-tokens [0-9]+' | awk '{print $2}')
|
|
66
|
+
NUM_INTENTS=$(echo "$ARGUMENTS" | grep -oE -- '--num-intents [0-9]+' | awk '{print $2}')
|
|
67
|
+
|
|
68
|
+
[ -z "$SEED" ] && SEED=42
|
|
69
|
+
[ -z "$MAX_TOKENS" ] && MAX_TOKENS=500
|
|
70
|
+
[ -z "$NUM_INTENTS" ] && NUM_INTENTS=5
|
|
71
|
+
|
|
72
|
+
if [ -z "$PROMPT_FILE" ]; then
|
|
73
|
+
echo "ERROR: prompt_file obrigatório"
|
|
74
|
+
exit 1
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
if [ ! -f "$PROMPT_FILE" ]; then
|
|
78
|
+
echo "ERROR: arquivo não encontrado: $PROMPT_FILE"
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 2. Detectar provider + framework
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# auto-detect provider
|
|
87
|
+
if [ -z "$PROVIDER" ]; then
|
|
88
|
+
if [ -n "$ANTHROPIC_API_KEY" ]; then
|
|
89
|
+
PROVIDER="anthropic"
|
|
90
|
+
elif [ -n "$OPENAI_API_KEY" ]; then
|
|
91
|
+
PROVIDER="openai"
|
|
92
|
+
else
|
|
93
|
+
echo "ERROR: nenhum provider detectado. Setar ANTHROPIC_API_KEY ou OPENAI_API_KEY"
|
|
94
|
+
exit 1
|
|
95
|
+
fi
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# detectar test framework
|
|
99
|
+
FRAMEWORK=""
|
|
100
|
+
if [ -f "package.json" ]; then
|
|
101
|
+
if jq -re '.devDependencies.vitest' package.json >/dev/null 2>&1; then FRAMEWORK="vitest"
|
|
102
|
+
elif jq -re '.devDependencies.jest' package.json >/dev/null 2>&1; then FRAMEWORK="jest"
|
|
103
|
+
fi
|
|
104
|
+
elif [ -f "pyproject.toml" ]; then
|
|
105
|
+
FRAMEWORK="pytest"
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
[ -z "$FRAMEWORK" ] && FRAMEWORK="vitest" # default sane
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 3. Dispatch para `legacy-characterizer` (modo prompt)
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
Task(
|
|
115
|
+
subagent_type="legacy-characterizer",
|
|
116
|
+
prompt="
|
|
117
|
+
target_file: ${PROMPT_FILE}
|
|
118
|
+
target_kind: prompt
|
|
119
|
+
provider: ${PROVIDER}
|
|
120
|
+
seed: ${SEED}
|
|
121
|
+
max_tokens: ${MAX_TOKENS}
|
|
122
|
+
num_intents: ${NUM_INTENTS}
|
|
123
|
+
${INPUTS_DIR:+inputs_dir: ${INPUTS_DIR}}
|
|
124
|
+
framework: ${FRAMEWORK}
|
|
125
|
+
|
|
126
|
+
Aplicar skill ai-prompt-characterization. Etapas:
|
|
127
|
+
1. Ler prompt + identificar inputs esperados (system prompt? user message format? tools?)
|
|
128
|
+
2. Gerar (ou ler de inputs-dir) ${NUM_INTENTS}+ inputs cobrindo intents distintas:
|
|
129
|
+
- concise: pedido curto, output esperado curto
|
|
130
|
+
- detailed: pedido elaborado, output esperado longo
|
|
131
|
+
- code-heavy: input/output com código
|
|
132
|
+
- edge case: input ambíguo
|
|
133
|
+
- adversarial: prompt injection attempt
|
|
134
|
+
3. Para cada intent: rodar LLM com temperature=0 + seed=${SEED}
|
|
135
|
+
4. Capturar text + finishReason + toolCalls (se function calling) + inputTokens + outputTokens + modelVersion
|
|
136
|
+
5. Sanitizar: timestamps, UUIDs, datas relativas, valores monetários, versões
|
|
137
|
+
6. Salvar como snapshot tests usando ${FRAMEWORK}
|
|
138
|
+
7. Cobertura behavioral = % intents cobertas (não % linhas)
|
|
139
|
+
"
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 4. Pós-output
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
═══════════════════════════════════════════════════════════
|
|
147
|
+
framework ► CARACTERIZAR-PROMPT ▸ tests/characterization/prompts/...
|
|
148
|
+
═══════════════════════════════════════════════════════════
|
|
149
|
+
|
|
150
|
+
[output do legacy-characterizer em modo prompt]
|
|
151
|
+
|
|
152
|
+
## ⚠ REVISÃO MANUAL OBRIGATÓRIA
|
|
153
|
+
|
|
154
|
+
Snapshots gerados — leia cada um antes de commit:
|
|
155
|
+
1. Verificar nenhum PII/secret persiste pós-sanitização
|
|
156
|
+
2. Verificar nenhum timestamp/UUID/data relativa unredacted
|
|
157
|
+
3. Confirmar finishReason esperado (stop vs length vs tool_use)
|
|
158
|
+
4. Para tool_uses: confirmar tool name + input shape
|
|
159
|
+
|
|
160
|
+
## Próximos passos
|
|
161
|
+
|
|
162
|
+
1. **Revisar snapshots** manualmente
|
|
163
|
+
2. **Rodar suite local:**
|
|
164
|
+
- JS/TS: `npm test -- tests/characterization/prompts`
|
|
165
|
+
- Python: `pytest tests/characterization/prompts`
|
|
166
|
+
3. **Commit** como `chore: characterize <prompt-name>`
|
|
167
|
+
4. **Configurar CI:**
|
|
168
|
+
- `tests/characterization/prompts/**` rodam em PR que toca `prompts/**`
|
|
169
|
+
- Diff vermelho = mudança comportamental detectada → review humano
|
|
170
|
+
5. **Configurar nightly** para detectar drift de model upstream:
|
|
171
|
+
- Anthropic publica Claude 4.8 → re-run characterization → snapshot diff
|
|
172
|
+
6. **Custo:** ~${NUM_INTENTS} × ($0.015/1k input tokens × 2k = $0.03 + output) ≈ $0.10-0.50/run
|
|
173
|
+
|
|
174
|
+
## Cross-suite
|
|
175
|
+
|
|
176
|
+
- **/caracterizar** (v1.12) — characterization de código (não prompt) — análogo
|
|
177
|
+
- **`llm-as-dependency`** skill — fakear LLM em business logic tests (não esses tests)
|
|
178
|
+
- **`legacy-api-only-applications`** skill — LLM provider é caso especial de API external
|
|
179
|
+
- **/instrumentar-fase** (v1.9) — instrumenta consumer de prompt (latency, tokens)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
</process>
|
|
183
|
+
|
|
184
|
+
<success_criteria>
|
|
185
|
+
- [ ] $ARGUMENTS parseados
|
|
186
|
+
- [ ] Provider detectado automaticamente OU especificado
|
|
187
|
+
- [ ] Framework de teste detectado
|
|
188
|
+
- [ ] `legacy-characterizer` invocado em modo prompt
|
|
189
|
+
- [ ] ≥ 5 intents cobrindo grupos canônicos (concise/detailed/code/edge/adversarial)
|
|
190
|
+
- [ ] temperature=0 + seed=fixo aplicado
|
|
191
|
+
- [ ] Sanitização específica para outputs LLM aplicada
|
|
192
|
+
- [ ] Tests rodam contra LLM real apenas em characterization (não em business logic tests)
|
|
193
|
+
- [ ] Próximos passos: review, commit, CI config, nightly drift detection
|
|
194
|
+
- [ ] Cross-suite com llm-as-dependency e legacy-api-only-applications
|
|
195
|
+
</success_criteria>
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: caracterizar
|
|
3
|
+
description: Invoca legacy-characterizer — gera characterization tests (cap 13 Feathers) capturando comportamento atual como golden snapshots; cobre 5+ grupos de equivalência canônicos; valida cobertura via mutation testing.
|
|
4
|
+
argument-hint: "<target_file> [--symbol <name>] [--min-inputs N] [--gap-fill] [--fixtures-dir <path>] [--no-mutation]"
|
|
5
|
+
allowed-tools:
|
|
6
|
+
- Read
|
|
7
|
+
- Write
|
|
8
|
+
- Edit
|
|
9
|
+
- Bash
|
|
10
|
+
- Grep
|
|
11
|
+
- Glob
|
|
12
|
+
- Task
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<objective>
|
|
16
|
+
Caracterizar arquivo de código legado (sem testes) gerando suite de characterization tests que congelam comportamento atual como oracle imutável durante refactor. Invoca o agente [`legacy-characterizer`](../agents/legacy-characterizer.md) que aplica a skill [`legacy-characterization-tests`](../skills/legacy-characterization-tests/SKILL.md) — 7 grupos canônicos de equivalência (empty/typical/boundary-low/boundary-up/recoverable-invalid/fatal-invalid/side-effect-heavy), golden snapshots com sanitização de PII, validação behavioral via mutation testing.
|
|
17
|
+
|
|
18
|
+
**Cria/Atualiza:**
|
|
19
|
+
- `tests/characterization/<file_stem>/` — suite de testes + snapshots + fakes auxiliares
|
|
20
|
+
- `tests/characterization/<file_stem>/README.md` — anotações de bugs preservados, fonte do oracle
|
|
21
|
+
|
|
22
|
+
**Após:** o user tem safety net que detecta regressão imediata em refactor. Gate `refactor-safety-auditor` muda de BLOCK → GO. Refactor pode prosseguir com `cover-and-modify` em vez de `edit-and-pray`.
|
|
23
|
+
</objective>
|
|
24
|
+
|
|
25
|
+
<context>
|
|
26
|
+
**Argumentos:**
|
|
27
|
+
- `<target_file>` — caminho do arquivo a caracterizar (relativo ao project root) — OBRIGATÓRIO
|
|
28
|
+
- `--symbol <name>` — caracterizar apenas símbolo específico (default: todos os exports)
|
|
29
|
+
- `--min-inputs N` — número mínimo de inputs (default: 8)
|
|
30
|
+
- `--gap-fill` — modo gap-fill: caracterizar APENAS o que falta para atingir 70% behavioral coverage (não recriar o que existe)
|
|
31
|
+
- `--fixtures-dir <path>` — diretório de payloads reais capturados (substitui inputs sintéticos por reais)
|
|
32
|
+
- `--no-mutation` — skip mutation testing após geração (default: roda se ferramenta detectada)
|
|
33
|
+
- `--output-dir <path>` — diretório base de output (default: `tests/characterization/<file_stem>/`)
|
|
34
|
+
|
|
35
|
+
**Exemplos:**
|
|
36
|
+
```
|
|
37
|
+
/caracterizar src/orders/handler.ts # caracterização completa, defaults
|
|
38
|
+
/caracterizar src/orders/handler.ts --symbol processOrder # só um método
|
|
39
|
+
/caracterizar src/orders/handler.ts --gap-fill # só preenche lacunas (re-rodar pós-refactor)
|
|
40
|
+
/caracterizar supabase/functions/webhook/index.ts \
|
|
41
|
+
--fixtures-dir .planning/captured-payloads/webhook # usa payloads reais
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Pré-requisitos:**
|
|
45
|
+
- Arquivo deve compilar/parsear no projeto atual
|
|
46
|
+
- Test framework instalado (Vitest, Jest, pytest, JUnit, go-test, etc.)
|
|
47
|
+
- (Recomendado) ferramenta de mutation testing instalada — Stryker (JS/TS), mutmut (Py), Pitest (Java)
|
|
48
|
+
- (Opcional) coverage tool com summary acessível (Istanbul/c8 para JS, coverage.py, JaCoCo)
|
|
49
|
+
|
|
50
|
+
**Quando este comando é o caminho certo:**
|
|
51
|
+
- Arquivo > 200 linhas com cobertura < 60% e mudança comportamental planejada
|
|
52
|
+
- Webhook/edge function/API pública sendo modificada
|
|
53
|
+
- Gate `refactor-safety-auditor` retornou BLOCK
|
|
54
|
+
- Refactor de monster method (cap 22) iniciando
|
|
55
|
+
|
|
56
|
+
**Quando NÃO é o caminho:**
|
|
57
|
+
- Arquivo trivial (< 50 linhas, sem branches significativas) — testes diretos sem ceremonial
|
|
58
|
+
- Mudança é apenas adicionar comportamento (sprout/wrap) — usar `/refactor-seguro --mode=sprout`
|
|
59
|
+
- Mudança é apenas mecânica (rename, extract-contiguous-block) — usar `/refactor-seguro --mode=safe-extract`
|
|
60
|
+
- Bug fix com TDD — TDD test do COMPORTAMENTO CORRETO é o caminho, não characterization
|
|
61
|
+
</context>
|
|
62
|
+
|
|
63
|
+
<process>
|
|
64
|
+
|
|
65
|
+
## 1. Parsear argumentos
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# PT-BR: extrair primeiro positional como target_file
|
|
69
|
+
TARGET_FILE=$(echo "$ARGUMENTS" | awk '{print $1}')
|
|
70
|
+
SYMBOL=$(echo "$ARGUMENTS" | grep -oE -- '--symbol [^ ]+' | awk '{print $2}')
|
|
71
|
+
MIN_INPUTS=$(echo "$ARGUMENTS" | grep -oE -- '--min-inputs [0-9]+' | awk '{print $2}')
|
|
72
|
+
FIXTURES_DIR=$(echo "$ARGUMENTS" | grep -oE -- '--fixtures-dir [^ ]+' | awk '{print $2}')
|
|
73
|
+
OUTPUT_DIR=$(echo "$ARGUMENTS" | grep -oE -- '--output-dir [^ ]+' | awk '{print $2}')
|
|
74
|
+
GAP_FILL=false
|
|
75
|
+
NO_MUTATION=false
|
|
76
|
+
|
|
77
|
+
echo "$ARGUMENTS" | grep -qE -- '--gap-fill' && GAP_FILL=true
|
|
78
|
+
echo "$ARGUMENTS" | grep -qE -- '--no-mutation' && NO_MUTATION=true
|
|
79
|
+
|
|
80
|
+
[ -z "$MIN_INPUTS" ] && MIN_INPUTS=8
|
|
81
|
+
|
|
82
|
+
if [ -z "$TARGET_FILE" ]; then
|
|
83
|
+
echo "ERROR: target_file é obrigatório."
|
|
84
|
+
echo "Uso: /caracterizar <target_file> [opções]"
|
|
85
|
+
exit 1
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
if [ ! -f "$TARGET_FILE" ]; then
|
|
89
|
+
echo "ERROR: arquivo não encontrado: $TARGET_FILE"
|
|
90
|
+
exit 1
|
|
91
|
+
fi
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 2. Validar pré-requisitos
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# PT-BR: detectar test framework + alertar se ausente
|
|
98
|
+
FRAMEWORK_OK=false
|
|
99
|
+
case "$TARGET_FILE" in
|
|
100
|
+
*.ts|*.tsx|*.js|*.jsx|*.mjs)
|
|
101
|
+
if [ -f "package.json" ]; then
|
|
102
|
+
jq -re '.devDependencies | (.vitest // .jest)' package.json >/dev/null 2>&1 && FRAMEWORK_OK=true
|
|
103
|
+
fi
|
|
104
|
+
;;
|
|
105
|
+
*.py)
|
|
106
|
+
pip show pytest >/dev/null 2>&1 && FRAMEWORK_OK=true
|
|
107
|
+
;;
|
|
108
|
+
*.java)
|
|
109
|
+
[ -f pom.xml ] || [ -f build.gradle ] && FRAMEWORK_OK=true
|
|
110
|
+
;;
|
|
111
|
+
*.go)
|
|
112
|
+
[ -f go.mod ] && FRAMEWORK_OK=true
|
|
113
|
+
;;
|
|
114
|
+
esac
|
|
115
|
+
|
|
116
|
+
if [ "$FRAMEWORK_OK" = false ]; then
|
|
117
|
+
echo "⚠ Test framework não detectado. Agent pode gerar testes mas execução exigirá setup."
|
|
118
|
+
fi
|
|
119
|
+
|
|
120
|
+
# PT-BR: avisar se gap-fill mas não há characterization existente
|
|
121
|
+
if [ "$GAP_FILL" = true ]; then
|
|
122
|
+
STEM=$(basename "$TARGET_FILE" | sed 's/\.[^.]*$//')
|
|
123
|
+
if ! find tests test __tests__ -path "*characterization*$STEM*" 2>/dev/null | head -1 | grep -q .; then
|
|
124
|
+
echo "⚠ --gap-fill solicitado mas nenhum characterization existente encontrado."
|
|
125
|
+
echo " Caindo em modo full-characterization."
|
|
126
|
+
GAP_FILL=false
|
|
127
|
+
fi
|
|
128
|
+
fi
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 3. Dispatch para `legacy-characterizer`
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
Task(
|
|
135
|
+
subagent_type="legacy-characterizer",
|
|
136
|
+
prompt="
|
|
137
|
+
target_file: ${TARGET_FILE}
|
|
138
|
+
${SYMBOL:+target_symbol: ${SYMBOL}}
|
|
139
|
+
min_inputs: ${MIN_INPUTS}
|
|
140
|
+
${FIXTURES_DIR:+payload_fixtures_dir: ${FIXTURES_DIR}}
|
|
141
|
+
${OUTPUT_DIR:+output_dir: ${OUTPUT_DIR}}
|
|
142
|
+
mutation_check: $([ "$NO_MUTATION" = true ] && echo false || echo true)
|
|
143
|
+
mode: $([ "$GAP_FILL" = true ] && echo gap-fill || echo full)
|
|
144
|
+
|
|
145
|
+
Aplicar skill legacy-characterization-tests. Etapas canônicas:
|
|
146
|
+
1. Análise estática: identificar exports, parâmetros, deps de I/O, side effects, branches
|
|
147
|
+
2. Aplicar 7 grupos de equivalência canônicos (ou substituir por payloads reais se fixtures-dir fornecido)
|
|
148
|
+
3. Construir fakes mínimos para deps de I/O (DB, HTTP, FS, clock, random, UUID)
|
|
149
|
+
4. Executar código real com cada input + fakes; capturar return + sideEffects
|
|
150
|
+
5. Sanitizar (PII, secrets, UUIDs voláteis) antes de salvar como snapshot
|
|
151
|
+
6. Imprimir warning de revisão obrigatória dos snapshots
|
|
152
|
+
7. Validar cobertura behavioral via mutation testing (Stryker/mutmut/Pitest)
|
|
153
|
+
8. Output: tests/characterization/<file_stem>/ + README.md
|
|
154
|
+
|
|
155
|
+
Modo gap-fill (se aplicável): caracterizar APENAS branches/paths não cobertos pela suite existente; NÃO recriar tests existentes.
|
|
156
|
+
"
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 4. Pós-output: revisão obrigatória + integração com gate
|
|
161
|
+
|
|
162
|
+
Após o agent completar:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
═══════════════════════════════════════════════════════════
|
|
166
|
+
framework ► CARACTERIZAR ▸ tests/characterization/<file_stem>/
|
|
167
|
+
═══════════════════════════════════════════════════════════
|
|
168
|
+
|
|
169
|
+
[output do legacy-characterizer]
|
|
170
|
+
|
|
171
|
+
## ⚠ REVISÃO MANUAL OBRIGATÓRIA dos snapshots
|
|
172
|
+
|
|
173
|
+
Localização: tests/characterization/<file_stem>/__snapshots__/
|
|
174
|
+
|
|
175
|
+
Steps antes de commit:
|
|
176
|
+
1. Ler cada snapshot linha por linha
|
|
177
|
+
2. Marcar bugs conhecidos como comments inline (// BUG #X: ...)
|
|
178
|
+
3. Verificar redaction de PII/secrets adicional
|
|
179
|
+
4. Confirmar zero secrets/UUIDs locais expostos
|
|
180
|
+
|
|
181
|
+
Não commitar como `chore: characterize <file>` sem revisão.
|
|
182
|
+
|
|
183
|
+
## Próximos passos
|
|
184
|
+
|
|
185
|
+
1. **Revisar snapshots** — manualmente, todos os arquivos em __snapshots__/
|
|
186
|
+
2. **Rodar suite** — verificar todos verdes:
|
|
187
|
+
- JS/TS: `npm test -- tests/characterization/<file_stem>`
|
|
188
|
+
- Python: `pytest tests/characterization/<file_stem>`
|
|
189
|
+
- Java: `mvn test -Dtest='Characterization*'`
|
|
190
|
+
3. **Commit** — `chore: characterize <file_stem>` (PR separado, NÃO misturar com refactor)
|
|
191
|
+
4. **Re-auditar gate** — `/auditar-refactor <file>` deve agora retornar GO
|
|
192
|
+
5. **Iniciar refactor** — `/refactor-seguro <file>` (ou diretamente PR de refactor)
|
|
193
|
+
|
|
194
|
+
## Cross-suite
|
|
195
|
+
|
|
196
|
+
- Para sprout/wrap em vez de full characterization: `/refactor-seguro --mode=sprout <file>`
|
|
197
|
+
- Para safe-extract em vez de behavioral change: `/refactor-seguro --mode=safe-extract <file>`
|
|
198
|
+
- Para SLO protection durante refactor: `/instrumentar-fase` (v1.9 — captura behavioral diff)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
</process>
|
|
202
|
+
|
|
203
|
+
<success_criteria>
|
|
204
|
+
- [ ] $ARGUMENTS parseados (target_file obrigatório, 7 flags opcionais)
|
|
205
|
+
- [ ] Pré-requisitos validados (framework de teste detectado; warning se não)
|
|
206
|
+
- [ ] `legacy-characterizer` invocado via `Task(subagent_type=...)` com prompt completo (8 etapas)
|
|
207
|
+
- [ ] `tests/characterization/<file_stem>/` criado com tests + snapshots + fakes + README
|
|
208
|
+
- [ ] Output forwarded transparentemente do agent
|
|
209
|
+
- [ ] Warning de revisão manual emitido (snapshots NÃO são committed automaticamente)
|
|
210
|
+
- [ ] Próximos passos sugeridos: revisar, rodar, commitar, re-auditar gate, iniciar refactor
|
|
211
|
+
- [ ] Modo gap-fill respeitado se solicitado e characterization existente encontrada
|
|
212
|
+
</success_criteria>
|