@luanpdd/kit-mcp 1.10.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/gates/ai-prompt-stability.md +120 -0
- package/gates/legacy-refactor-safety.md +178 -0
- package/gates/observability-coverage.md +151 -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/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 +47 -0
- package/kit/agents/payload-capture-instrumenter.md +283 -0
- package/kit/agents/planner.md +29 -0
- package/kit/agents/prr-conductor.md +8 -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-edge-fn-writer.md +12 -0
- package/kit/agents/verifier.md +30 -0
- package/kit/commands/auditar-cascading.md +111 -0
- package/kit/commands/auditar-marco.md +44 -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/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 +41 -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 +40 -1
- 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/refactor-seguro.md +321 -0
- package/kit/commands/sre.md +3 -0
- package/kit/commands/storytelling.md +179 -0
- package/kit/skills/_shared-legacy/glossary.md +389 -0
- package/kit/skills/_shared-sre/glossary.md +139 -0
- package/kit/skills/ai-prompt-characterization/SKILL.md +335 -0
- package/kit/skills/cascading-failures/SKILL.md +307 -0
- package/kit/skills/four-golden-signals/SKILL.md +17 -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/release-engineering/SKILL.md +367 -0
- package/kit/skills/retry-strategies/SKILL.md +372 -0
- package/package.json +2 -2
package/kit/agents/verifier.md
CHANGED
|
@@ -55,6 +55,36 @@ A verificação reversa a partir do objetivo começa pelo resultado e trabalha d
|
|
|
55
55
|
Depois verifique cada nível na codebase real.
|
|
56
56
|
</core_principle>
|
|
57
57
|
|
|
58
|
+
<legacy_refactor_verification>
|
|
59
|
+
**Verificação especial para fases de refactor:**
|
|
60
|
+
|
|
61
|
+
Se PLAN.md tem tasks com `kind=refactor` em arquivos flagged (> 500 linhas OR contrato externo), aplique verificação adicional baseada na skill [`pre-refactor-characterization`](../skills/pre-refactor-characterization/SKILL.md) e [`legacy-characterization-tests`](../skills/legacy-characterization-tests/SKILL.md):
|
|
62
|
+
|
|
63
|
+
1. **Characterization tests existem?**
|
|
64
|
+
- Verificar `tests/characterization/<file_stem>/` ou equivalente
|
|
65
|
+
- Se ausente E refactor de risco aconteceu → **veredito: regressão indeterminável**
|
|
66
|
+
- Marca em VERIFICATION.md como gap crítico (não passa fase)
|
|
67
|
+
|
|
68
|
+
2. **Characterization tests passam VERDE?**
|
|
69
|
+
- Rodar suite com framework adequado (Vitest, Pytest, etc.)
|
|
70
|
+
- Snapshot diff = 0 → comportamento preservado → ✓
|
|
71
|
+
- Snapshot diff > 0 → comportamento mudou → investigar:
|
|
72
|
+
- Se documentado como behavior change intencional → ✓ com nota
|
|
73
|
+
- Se não documentado → **regressão real** → falha de fase
|
|
74
|
+
|
|
75
|
+
3. **Mutation kill score adequado?**
|
|
76
|
+
- Rodar mutation testing (Stryker / mutmut / Pitest)
|
|
77
|
+
- Kill ≥ 70% → safety net adequado
|
|
78
|
+
- Kill < 70% → warning (pode ter pontos cegos)
|
|
79
|
+
|
|
80
|
+
4. **Modo override usado?**
|
|
81
|
+
- Verificar `.planning/REFACTOR-SAFETY.md` com seção `Aprovação manual`
|
|
82
|
+
- Se ticket linkado existe e é válido → ✓ (débito documentado)
|
|
83
|
+
- Se sem ticket OR ticket inválido → falha de auditoria
|
|
84
|
+
|
|
85
|
+
Adicione resultados ao VERIFICATION.md em seção `## Legacy Refactor Verification`. Block phase close se characterization ausente em refactor de risco.
|
|
86
|
+
</legacy_refactor_verification>
|
|
87
|
+
|
|
58
88
|
<verification_process>
|
|
59
89
|
|
|
60
90
|
## Passo 0: Verificar Verificação Anterior
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: auditar-cascading
|
|
3
|
+
description: Invoca cascading-failures-auditor — audita código de serviço para 5 triggers de cascade (sem timeout, retry sem jitter, sem circuit breaker, sem deadline propagation, queue unbounded); gera CASCADING-AUDIT.md priorizado P0/P1/P2.
|
|
4
|
+
argument-hint: "[target_path] [--dimensions ...] [--severity P0|P1|P2|all]"
|
|
5
|
+
allowed-tools:
|
|
6
|
+
- Read
|
|
7
|
+
- Bash
|
|
8
|
+
- Grep
|
|
9
|
+
- Glob
|
|
10
|
+
- Task
|
|
11
|
+
- Write
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<objective>
|
|
15
|
+
Auditar código de serviço (Edge Function, handler HTTP, ou repo inteiro) para os 5 triggers canônicos de cascading failure (cap 22 livro Google SRE). Invoca o agente [`cascading-failures-auditor`](../agents/cascading-failures-auditor.md) que aplica a skill [`cascading-failures`](../skills/cascading-failures/SKILL.md) — defesa em camadas (timeout + retry com jitter + circuit breaker + deadline propagation + saturation gauge).
|
|
16
|
+
|
|
17
|
+
**Cria/Atualiza:**
|
|
18
|
+
- `.planning/CASCADING-AUDIT.md` — relatório priorizado P0/P1/P2 com diff sugerido por finding
|
|
19
|
+
|
|
20
|
+
**Após:** o user tem fila acionável de patches para prevenir cascade. Cap 22 — prevenção custa 1×, recuperação custa 100×.
|
|
21
|
+
</objective>
|
|
22
|
+
|
|
23
|
+
<context>
|
|
24
|
+
**Argumentos:**
|
|
25
|
+
- `[target_path]` — arquivo, diretório ou repo (default: `.`)
|
|
26
|
+
- `--dimensions <list>` — subset de `[timeouts, retry-jitter, circuit-breaker, deadline-prop, queue-bound, health-check, saturation-gauge]` (default: todas)
|
|
27
|
+
- `--severity P0|P1|P2|all` — filtro (default: all)
|
|
28
|
+
- `--output PATH` — caminho do output (default: `.planning/CASCADING-AUDIT.md`)
|
|
29
|
+
|
|
30
|
+
**Exemplos:**
|
|
31
|
+
```
|
|
32
|
+
/auditar-cascading # repo inteiro
|
|
33
|
+
/auditar-cascading supabase/functions/ # só Edge Functions
|
|
34
|
+
/auditar-cascading src/orders/handler.ts # arquivo específico
|
|
35
|
+
/auditar-cascading --severity P0 # só fix imediato
|
|
36
|
+
/auditar-cascading --dimensions timeouts,retry-jitter # foco em duas dims
|
|
37
|
+
```
|
|
38
|
+
</context>
|
|
39
|
+
|
|
40
|
+
<process>
|
|
41
|
+
|
|
42
|
+
## 1. Parsear argumentos
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
TARGET_PATH=$(echo "$ARGUMENTS" | awk '{print $1}')
|
|
46
|
+
[ -z "$TARGET_PATH" ] || [ "${TARGET_PATH:0:2}" = "--" ] && TARGET_PATH="."
|
|
47
|
+
DIMENSIONS=$(echo "$ARGUMENTS" | grep -oE -- '--dimensions [^ ]+' | awk '{print $2}')
|
|
48
|
+
SEVERITY=$(echo "$ARGUMENTS" | grep -oE -- '--severity [^ ]+' | awk '{print $2}')
|
|
49
|
+
OUTPUT_PATH=$(echo "$ARGUMENTS" | grep -oE -- '--output [^ ]+' | awk '{print $2}')
|
|
50
|
+
|
|
51
|
+
[ -z "$OUTPUT_PATH" ] && OUTPUT_PATH=".planning/CASCADING-AUDIT.md"
|
|
52
|
+
mkdir -p "$(dirname "$OUTPUT_PATH")"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 2. Dispatch para `cascading-failures-auditor`
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
Task(
|
|
59
|
+
subagent_type="cascading-failures-auditor",
|
|
60
|
+
prompt="
|
|
61
|
+
target_path: ${TARGET_PATH}
|
|
62
|
+
output_path: ${OUTPUT_PATH}
|
|
63
|
+
${DIMENSIONS:+dimensions: ${DIMENSIONS}}
|
|
64
|
+
${SEVERITY:+severity_filter: ${SEVERITY}}
|
|
65
|
+
|
|
66
|
+
Aplicar skill cascading-failures + retry-strategies + load-shedding-graceful-degradation. Detectar 5 triggers canônicos:
|
|
67
|
+
1. Sem timeout em chamadas externas (fetch/axios/http sem AbortSignal/timeout)
|
|
68
|
+
2. Retry sem jitter (setTimeout exponencial sem Math.random)
|
|
69
|
+
3. Sem circuit breaker em deps externas
|
|
70
|
+
4. Sem deadline propagation (handler sem header x-deadline)
|
|
71
|
+
5. Queue unbounded sem drop policy
|
|
72
|
+
|
|
73
|
+
Priorizar P0 (fix imediato) / P1 (próximo sprint) / P2 (best practice). Gerar diff sugerido para cada P0/P1.
|
|
74
|
+
"
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 3. Pós-output
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
═══════════════════════════════════════════════════════════
|
|
82
|
+
framework ► AUDITAR-CASCADING ▸ ${OUTPUT_PATH}
|
|
83
|
+
═══════════════════════════════════════════════════════════
|
|
84
|
+
|
|
85
|
+
[output do agent]
|
|
86
|
+
|
|
87
|
+
## Próximos passos
|
|
88
|
+
|
|
89
|
+
1. **Aplicar P0 imediato** — patches são pequenos (5-15 min cada)
|
|
90
|
+
2. **/load-shedding <fn>** — adicionar defesas server-side complementares
|
|
91
|
+
3. **/golden-signals <fn>** (v1.10) — adicionar Saturation gauge (early warning de cascade)
|
|
92
|
+
4. **/prr <service>** (v1.10) — Axe 4 (Capacity Planning) consume este audit
|
|
93
|
+
5. **Game day exercise** mensal — validar resilience em staging
|
|
94
|
+
|
|
95
|
+
## Cross-suite
|
|
96
|
+
|
|
97
|
+
- v1.9 Observability — Saturation alert dispara load shed antes de cascade
|
|
98
|
+
- v1.10 SRE — PRR Axe 4 + Axe 5 consume
|
|
99
|
+
- v1.11 SRE Resilience — esse audit
|
|
100
|
+
- v1.12 Legacy — refactor pode introduzir/remover defesas; pre-refactor-characterization gate
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
</process>
|
|
104
|
+
|
|
105
|
+
<success_criteria>
|
|
106
|
+
- [ ] $ARGUMENTS parseados (target_path opcional, default cwd)
|
|
107
|
+
- [ ] `cascading-failures-auditor` invocado via Task
|
|
108
|
+
- [ ] CASCADING-AUDIT.md criado pelo agent
|
|
109
|
+
- [ ] Output forwarded transparentemente
|
|
110
|
+
- [ ] Cross-references com /load-shedding, /golden-signals, /prr
|
|
111
|
+
</success_criteria>
|
|
@@ -134,4 +134,47 @@ Para esses casos: `workflow.audit_milestone_toil = false`. Para projetos team-ba
|
|
|
134
134
|
- "Toil ≠ overhead" → overhead inclui meetings, planning, code review (necessário, não automatizável); toil é só o automatizable
|
|
135
135
|
|
|
136
136
|
**REQ:** INT-FW-V2-03.
|
|
137
|
-
</sre_integration>
|
|
137
|
+
</sre_integration>
|
|
138
|
+
|
|
139
|
+
<legacy_refactor_integration>
|
|
140
|
+
**Legacy refactor safety audit (opt-in):**
|
|
141
|
+
|
|
142
|
+
Quando `workflow.audit_milestone_legacy_refactor = true` (default: false em projetos < 50% OMM maturity, true acima), o workflow inclui passo de auditoria de refactor safety:
|
|
143
|
+
|
|
144
|
+
```text
|
|
145
|
+
Para cada arquivo modificado por tasks com kind=refactor no milestone:
|
|
146
|
+
Task(
|
|
147
|
+
subagent_type="refactor-safety-auditor",
|
|
148
|
+
prompt="
|
|
149
|
+
target_file: <file>
|
|
150
|
+
change_kind: refactor
|
|
151
|
+
mode: blocking
|
|
152
|
+
output_path: .planning/REFACTOR-SAFETY-<file_stem>.md
|
|
153
|
+
|
|
154
|
+
Aplicar skill pre-refactor-characterization. Validar retroativamente que safety net foi aplicado.
|
|
155
|
+
"
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Critérios de aprovação:**
|
|
160
|
+
- Cada refactor de risco no milestone tem characterization tests linkados E pass verde
|
|
161
|
+
- Cada `--mode=override` tem ticket linkado válido (ainda aberto OR resolvido com follow-up)
|
|
162
|
+
- Mutation kill score ≥ 70% nos arquivos refatorados (warning se line cov OK mas mutation baixo)
|
|
163
|
+
|
|
164
|
+
**Resultado de regression:**
|
|
165
|
+
- 0 refactors sem char → audit aprovado
|
|
166
|
+
- 1+ refactors sem char e sem override → audit fail; bloqueia close de milestone até resolução
|
|
167
|
+
- 1+ overrides com tickets ainda abertos > 90 dias → warning explícito (débito técnico envelhecido)
|
|
168
|
+
|
|
169
|
+
Skill canônica: [`pre-refactor-characterization`](../skills/pre-refactor-characterization/SKILL.md)
|
|
170
|
+
Cross-ref ativo: `omm-auditor` Capacidade 1 (Resilience) score consulta REFACTOR-SAFETY summaries para fator "% refactors com safety net"; baixa adequação reduz score.
|
|
171
|
+
|
|
172
|
+
**Quando desligar gate:**
|
|
173
|
+
- Projeto greenfield com < 3 meses de idade (legacy code não existe ainda)
|
|
174
|
+
- Solo dev side project sem stakes de produção (audit é overhead)
|
|
175
|
+
- Toda codebase é < 50% código não-trivial (a maior parte é config/markdown/tests)
|
|
176
|
+
|
|
177
|
+
Para esses casos: `workflow.audit_milestone_legacy_refactor = false`. Para projetos com stakes de produção e equipe ≥ 2 pessoas, **manter `true`**.
|
|
178
|
+
|
|
179
|
+
**REQ:** INT-LEGACY-FW-01.
|
|
180
|
+
</legacy_refactor_integration>
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: auditar-observabilidade-cobertura
|
|
3
|
+
description: Audita projeto Supabase mostrando X/N Edge Functions com 4 golden signals + Y/N com SLO + Z/N com burn alert + W/N com characterization tests. Top 5 críticas (por traffic 30d) sem cobertura. User-request explícito.
|
|
4
|
+
argument-hint: "[--traffic-window 30d] [--top-n 5] [--dimensions signals,slo,burn-alert,characterization] [--output PATH]"
|
|
5
|
+
allowed-tools:
|
|
6
|
+
- Read
|
|
7
|
+
- Bash
|
|
8
|
+
- Grep
|
|
9
|
+
- Glob
|
|
10
|
+
- Task
|
|
11
|
+
- Write
|
|
12
|
+
- mcp__supabase__list_edge_functions
|
|
13
|
+
- mcp__supabase__get_logs
|
|
14
|
+
- mcp__supabase__execute_sql
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<objective>
|
|
18
|
+
**O comando que você roda hoje pra ver o tamanho do buraco e priorizar.** Audit horizontal de cobertura cross-suite (Observabilidade v1.9 + SRE v1.10 + Legacy v1.12). Roda contra projeto Supabase, gera relatório:
|
|
19
|
+
|
|
20
|
+
- Edge functions emitindo 4 golden signals: **X / N**
|
|
21
|
+
- Edge functions com SLO definido: **Y / N**
|
|
22
|
+
- Edge functions com burn rate alert: **Z / N**
|
|
23
|
+
- Edge functions com characterization tests: **W / N**
|
|
24
|
+
- **Top 5 funções mais críticas (por chamadas 30d) sem cobertura completa**
|
|
25
|
+
|
|
26
|
+
Invoca o agente [`observability-coverage-auditor`](../agents/observability-coverage-auditor.md) que cross-references skills v1.9 + v1.10 + v1.12.
|
|
27
|
+
|
|
28
|
+
**Cria/Atualiza:**
|
|
29
|
+
- `.planning/OBSERVABILITY-COVERAGE.md` — relatório scored com tabela X/N por dimensão + top críticas + recomendações priorizadas
|
|
30
|
+
|
|
31
|
+
**Após:** o user vê tamanho do buraco quantitativamente e tem fila ordenada por (traffic × missing dimensions). As 2 que ele instrumentou às pressas viram baseline; as outras N entram na fila ordenada.
|
|
32
|
+
</objective>
|
|
33
|
+
|
|
34
|
+
<context>
|
|
35
|
+
**Argumentos:**
|
|
36
|
+
- `--traffic-window 30d` — janela para criticidade (default: 30d)
|
|
37
|
+
- `--top-n 5` — quantas críticas listar (default: 5)
|
|
38
|
+
- `--dimensions <list>` — quais dimensões auditar (default: `signals,slo,burn-alert,characterization`)
|
|
39
|
+
- `--output PATH` — caminho do output (default: `.planning/OBSERVABILITY-COVERAGE.md`)
|
|
40
|
+
|
|
41
|
+
**Exemplos:**
|
|
42
|
+
```
|
|
43
|
+
/auditar-observabilidade-cobertura # defaults
|
|
44
|
+
/auditar-observabilidade-cobertura --top-n 10 # listar top 10
|
|
45
|
+
/auditar-observabilidade-cobertura --dimensions signals,slo # só 2 dimensões
|
|
46
|
+
/auditar-observabilidade-cobertura --traffic-window 7d # janela menor
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Pré-requisitos:**
|
|
50
|
+
- Projeto Supabase (`supabase/config.toml` presente)
|
|
51
|
+
- MCP Supabase conectado para traffic data + Edge Functions list (recomendado)
|
|
52
|
+
- Sem MCP: agent reverte para enumerate via filesystem (sem traffic data → top-N por filesystem only)
|
|
53
|
+
|
|
54
|
+
**Quando este comando é o caminho:**
|
|
55
|
+
- Você quer "ver o buraco" antes de priorizar instrumentação
|
|
56
|
+
- Você instrumentou algumas Edge Functions ad-hoc; agora quer audit estruturado das outras
|
|
57
|
+
- Audit trimestral cross-suite
|
|
58
|
+
- Pré-requisito de `/concluir-marco` quando `workflow.observability_coverage_threshold` opt-in
|
|
59
|
+
- `/auditar-marco` chain (audit milestone consume este)
|
|
60
|
+
</context>
|
|
61
|
+
|
|
62
|
+
<process>
|
|
63
|
+
|
|
64
|
+
## 1. Parsear argumentos
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
TRAFFIC_WINDOW=$(echo "$ARGUMENTS" | grep -oE -- '--traffic-window [^ ]+' | awk '{print $2}')
|
|
68
|
+
TOP_N=$(echo "$ARGUMENTS" | grep -oE -- '--top-n [0-9]+' | awk '{print $2}')
|
|
69
|
+
DIMENSIONS=$(echo "$ARGUMENTS" | grep -oE -- '--dimensions [^ ]+' | awk '{print $2}')
|
|
70
|
+
OUTPUT_PATH=$(echo "$ARGUMENTS" | grep -oE -- '--output [^ ]+' | awk '{print $2}')
|
|
71
|
+
|
|
72
|
+
[ -z "$TRAFFIC_WINDOW" ] && TRAFFIC_WINDOW="30d"
|
|
73
|
+
[ -z "$TOP_N" ] && TOP_N=5
|
|
74
|
+
[ -z "$DIMENSIONS" ] && DIMENSIONS="signals,slo,burn-alert,characterization"
|
|
75
|
+
[ -z "$OUTPUT_PATH" ] && OUTPUT_PATH=".planning/OBSERVABILITY-COVERAGE.md"
|
|
76
|
+
|
|
77
|
+
mkdir -p "$(dirname "$OUTPUT_PATH")"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 2. Validar pré-requisitos
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
PROJECT_ID=""
|
|
84
|
+
if [ -f "supabase/config.toml" ]; then
|
|
85
|
+
PROJECT_ID=$(grep -E '^project_id\s*=' supabase/config.toml | sed 's/.*= *"\(.*\)".*/\1/' | head -1)
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
# Detectar tier (Full vs Partial)
|
|
89
|
+
TIER="full"
|
|
90
|
+
if [ -z "$PROJECT_ID" ]; then
|
|
91
|
+
TIER="partial"
|
|
92
|
+
echo "ℹ project_id não detectado em supabase/config.toml — degradando para tier partial (sem traffic data)"
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
# Detectar Edge Functions via filesystem
|
|
96
|
+
NUM_EDGE_FNS=$(find supabase/functions -mindepth 1 -maxdepth 1 -type d 2>/dev/null | wc -l)
|
|
97
|
+
if [ "$NUM_EDGE_FNS" -eq 0 ]; then
|
|
98
|
+
echo "ERROR: nenhuma Edge Function detectada em supabase/functions/. Audit cancelado."
|
|
99
|
+
exit 1
|
|
100
|
+
fi
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 3. Dispatch para `observability-coverage-auditor`
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
Task(
|
|
107
|
+
subagent_type="observability-coverage-auditor",
|
|
108
|
+
prompt="
|
|
109
|
+
project_root: .
|
|
110
|
+
output_path: ${OUTPUT_PATH}
|
|
111
|
+
traffic_window: ${TRAFFIC_WINDOW}
|
|
112
|
+
top_n_critical: ${TOP_N}
|
|
113
|
+
dimensions: ${DIMENSIONS}
|
|
114
|
+
${PROJECT_ID:+project_id: ${PROJECT_ID}}
|
|
115
|
+
tier: ${TIER}
|
|
116
|
+
|
|
117
|
+
Aplicar skills (cross-suite v1.9+v1.10+v1.12). Etapas:
|
|
118
|
+
1. Enumerar Edge Functions (via mcp__supabase__list_edge_functions ou filesystem fallback)
|
|
119
|
+
2. Para cada Edge Function, auditar:
|
|
120
|
+
- 4 Golden Signals (grep por createHistogram/createCounter/createObservableGauge)
|
|
121
|
+
- SLO definido (.planning/slos/<name>.md ou .planning/SLO.md menção)
|
|
122
|
+
- Burn rate alert (config presente)
|
|
123
|
+
- Characterization tests (tests/characterization/<name>/ presente)
|
|
124
|
+
3. Coletar traffic 30d via mcp__supabase__get_logs (Tier Full) ou skip (Tier Partial)
|
|
125
|
+
4. Calcular criticality_score = traffic × missing_count
|
|
126
|
+
5. Compilar matriz + top ${TOP_N} críticas + recomendações priorizadas
|
|
127
|
+
6. Output: .planning/OBSERVABILITY-COVERAGE.md
|
|
128
|
+
"
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 4. Pós-output
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
═══════════════════════════════════════════════════════════
|
|
136
|
+
framework ► AUDITAR-OBSERVABILIDADE-COBERTURA ▸ ${OUTPUT_PATH}
|
|
137
|
+
═══════════════════════════════════════════════════════════
|
|
138
|
+
|
|
139
|
+
[output do observability-coverage-auditor]
|
|
140
|
+
|
|
141
|
+
## Próximos passos priorizados
|
|
142
|
+
|
|
143
|
+
1. **Atacar top 1 crítica primeiro** — comando direto:
|
|
144
|
+
- Se signals missing: `/golden-signals <function-path>`
|
|
145
|
+
- Se SLO missing: `/definir-slo <function-name>`
|
|
146
|
+
- Se char missing: `/caracterizar <function-path>`
|
|
147
|
+
- Se burn alert missing: configurar via `/burn-rate-status` + alert manager
|
|
148
|
+
|
|
149
|
+
2. **Continuar pela ordem de criticality** (top 2, 3, ...)
|
|
150
|
+
|
|
151
|
+
3. **Bulk approach** se há > 10 funções missing:
|
|
152
|
+
- Priorize SIGNALS primeiro (visibility é fundação)
|
|
153
|
+
- Depois SLO (define o que importa)
|
|
154
|
+
- Depois BURN ALERT (early warning)
|
|
155
|
+
- Depois CHARACTERIZATION (refactor safety)
|
|
156
|
+
|
|
157
|
+
4. **Auto-completion** via:
|
|
158
|
+
- `/observabilidade audit-coverage` — sinônimo deste comando
|
|
159
|
+
- `/observabilidade omm` — OMM scoring v1.9 que consume este audit
|
|
160
|
+
- `/auditar-marco` — milestone audit que opt-in invoca este
|
|
161
|
+
|
|
162
|
+
## Cross-suite
|
|
163
|
+
|
|
164
|
+
Este audit é o **HUB** que conecta as 3 suítes:
|
|
165
|
+
- v1.9 Observabilidade (golden signals + SLO + burn alert)
|
|
166
|
+
- v1.10 SRE (PRR Axe 2 Instrumentation + Axe 4 Capacity)
|
|
167
|
+
- v1.12 Legacy (characterization safety net)
|
|
168
|
+
|
|
169
|
+
Re-rodar trimestralmente OR após cada milestone com novas Edge Functions.
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
</process>
|
|
173
|
+
|
|
174
|
+
<success_criteria>
|
|
175
|
+
- [ ] $ARGUMENTS parseados (todos opcionais, defaults razoáveis)
|
|
176
|
+
- [ ] Project_id resolvido OU degradado para tier partial sem warning
|
|
177
|
+
- [ ] Edge Functions enumeradas (≥ 1 detectada)
|
|
178
|
+
- [ ] `observability-coverage-auditor` invocado via Task
|
|
179
|
+
- [ ] Output forwarded transparentemente
|
|
180
|
+
- [ ] Próximos passos PRIORIZADOS com comandos prontos para copy-paste
|
|
181
|
+
- [ ] Cross-references com /observabilidade, /auditar-marco, /golden-signals, /caracterizar
|
|
182
|
+
- [ ] Atende explicitamente ao user-request "comando que você roda hoje pra ver o tamanho do buraco"
|
|
183
|
+
</success_criteria>
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: auditar-refactor
|
|
3
|
+
description: Invoca refactor-safety-auditor — gate canônico antes de qualquer refactor. Coleta evidências (linhas, contrato externo, coverage, mutation) e retorna veredito GO/BLOCK/WARN/GO-OVERRIDE. Bloqueia refactor de risco sem characterization.
|
|
4
|
+
argument-hint: "<target_file> [--change-kind refactor|sprout|safe-extract|override] [--mode blocking|consultive] [--ticket REQ-N] [--reason \"...\"]"
|
|
5
|
+
allowed-tools:
|
|
6
|
+
- Read
|
|
7
|
+
- Write
|
|
8
|
+
- Bash
|
|
9
|
+
- Grep
|
|
10
|
+
- Glob
|
|
11
|
+
- Task
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<objective>
|
|
15
|
+
Auditar arquivo alvo de refactor ANTES da execução para decidir se safety net (characterization tests) é adequado. Invoca o agente [`refactor-safety-auditor`](../agents/refactor-safety-auditor.md) que aplica a skill [`pre-refactor-characterization`](../skills/pre-refactor-characterization/SKILL.md) — 3 critérios de risco canônicos (tamanho > 500 linhas, contrato externo, cobertura < 60%) + matriz de decisão.
|
|
16
|
+
|
|
17
|
+
**Cria/Atualiza:**
|
|
18
|
+
- `.planning/REFACTOR-SAFETY.md` — relatório com evidências, veredito, caminhos recomendados, audit trail
|
|
19
|
+
|
|
20
|
+
**Após:** o user tem decisão **objetiva** (não gut-feeling) sobre se refactor pode prosseguir. Se BLOCK, oferece 4 caminhos concretos. Se GO-OVERRIDE, registra ticket + reason para débito técnico.
|
|
21
|
+
</objective>
|
|
22
|
+
|
|
23
|
+
<context>
|
|
24
|
+
**Argumentos:**
|
|
25
|
+
- `<target_file>` — caminho do arquivo a auditar — OBRIGATÓRIO
|
|
26
|
+
- `--change-kind <kind>` — tipo da mudança (default: `refactor`):
|
|
27
|
+
- `refactor` — mudança comportamental (gate roda completo)
|
|
28
|
+
- `sprout` — adiciona via sprout method/class (legado intocado, gate libera com 100% no novo)
|
|
29
|
+
- `safe-extract` — refactor mecânico (rename, IDE-extract bloco contíguo, sem mudar control flow)
|
|
30
|
+
- `override` — bypass com justificativa (requer --ticket + --reason)
|
|
31
|
+
- `--mode blocking|consultive` — força modo do gate (default: lido de `.planning/config.json`)
|
|
32
|
+
- `--ticket REQ-N` — ticket linkado (obrigatório com --change-kind=override)
|
|
33
|
+
- `--reason "<texto>"` — justificativa (obrigatória com --change-kind=override)
|
|
34
|
+
- `--output PATH` — caminho do output (default: `.planning/REFACTOR-SAFETY.md`)
|
|
35
|
+
|
|
36
|
+
**Exemplos:**
|
|
37
|
+
```
|
|
38
|
+
/auditar-refactor src/orders/handler.ts # default refactor
|
|
39
|
+
/auditar-refactor src/orders/handler.ts --change-kind sprout # libera (sprout)
|
|
40
|
+
/auditar-refactor src/orders/handler.ts --change-kind safe-extract # libera (mecânico)
|
|
41
|
+
/auditar-refactor src/orders/handler.ts \
|
|
42
|
+
--change-kind override --ticket REQ-2026-Q2-1234 \
|
|
43
|
+
--reason "hot fix de SEV1, char será adicionado em REQ-2026-Q2-1235" # bypass com audit trail
|
|
44
|
+
/auditar-refactor src/orders/handler.ts --mode consultive # warning em vez de block
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Fluxo típico:**
|
|
48
|
+
1. `/discutir-fase` detecta refactor intent → automaticamente invoca este comando
|
|
49
|
+
2. Veredito BLOCK → user escolhe um dos 4 caminhos (caracterizar, sprout, safe-extract, override)
|
|
50
|
+
3. Aplicar caminho + re-rodar este comando até veredito GO
|
|
51
|
+
4. Refactor executado com confiança
|
|
52
|
+
|
|
53
|
+
**Quando invocar manualmente:**
|
|
54
|
+
- Antes de planejar fase de refactor
|
|
55
|
+
- Antes de PR de refactor de arquivo grande
|
|
56
|
+
- Periodicamente em milestones para identificar gaps de coverage
|
|
57
|
+
- Como parte de `/auditar-marco` quando `workflow.audit_milestone_legacy_refactor=true`
|
|
58
|
+
</context>
|
|
59
|
+
|
|
60
|
+
<process>
|
|
61
|
+
|
|
62
|
+
## 1. Parsear argumentos
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
TARGET_FILE=$(echo "$ARGUMENTS" | awk '{print $1}')
|
|
66
|
+
CHANGE_KIND=$(echo "$ARGUMENTS" | grep -oE -- '--change-kind [^ ]+' | awk '{print $2}')
|
|
67
|
+
MODE=$(echo "$ARGUMENTS" | grep -oE -- '--mode [^ ]+' | awk '{print $2}')
|
|
68
|
+
TICKET=$(echo "$ARGUMENTS" | grep -oE -- '--ticket [^ ]+' | awk '{print $2}')
|
|
69
|
+
REASON=$(echo "$ARGUMENTS" | grep -oE -- '--reason "[^"]+"' | sed 's/--reason "\(.*\)"/\1/')
|
|
70
|
+
OUTPUT_PATH=$(echo "$ARGUMENTS" | grep -oE -- '--output [^ ]+' | awk '{print $2}')
|
|
71
|
+
|
|
72
|
+
[ -z "$CHANGE_KIND" ] && CHANGE_KIND="refactor"
|
|
73
|
+
[ -z "$OUTPUT_PATH" ] && OUTPUT_PATH=".planning/REFACTOR-SAFETY.md"
|
|
74
|
+
|
|
75
|
+
if [ -z "$TARGET_FILE" ]; then
|
|
76
|
+
echo "ERROR: target_file é obrigatório."
|
|
77
|
+
echo "Uso: /auditar-refactor <target_file> [opções]"
|
|
78
|
+
exit 1
|
|
79
|
+
fi
|
|
80
|
+
|
|
81
|
+
if [ ! -f "$TARGET_FILE" ]; then
|
|
82
|
+
echo "ERROR: arquivo não encontrado: $TARGET_FILE"
|
|
83
|
+
exit 1
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
# PT-BR: validar override → exige ticket + reason
|
|
87
|
+
if [ "$CHANGE_KIND" = "override" ]; then
|
|
88
|
+
if [ -z "$TICKET" ] || [ -z "$REASON" ]; then
|
|
89
|
+
echo "ERROR: --change-kind=override requer --ticket REQ-N E --reason \"<texto>\"."
|
|
90
|
+
echo "Sem audit trail, override é proibido."
|
|
91
|
+
exit 1
|
|
92
|
+
fi
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
mkdir -p "$(dirname "$OUTPUT_PATH")"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 2. Detectar mode default via config + omm
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# PT-BR: ler config para mode default
|
|
102
|
+
CONFIG_MODE=""
|
|
103
|
+
if [ -f ".planning/config.json" ] && command -v jq >/dev/null; then
|
|
104
|
+
GATE_BLOCKING=$(jq -r '.workflow.legacy_refactor_gate_blocking // empty' .planning/config.json)
|
|
105
|
+
if [ "$GATE_BLOCKING" = "true" ]; then
|
|
106
|
+
CONFIG_MODE="blocking"
|
|
107
|
+
elif [ "$GATE_BLOCKING" = "false" ]; then
|
|
108
|
+
CONFIG_MODE="consultive"
|
|
109
|
+
fi
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
# PT-BR: integração com omm-auditor — Capacidade 1 (Resilience) calibra mode
|
|
113
|
+
if [ -z "$MODE" ] && [ -z "$CONFIG_MODE" ]; then
|
|
114
|
+
if [ -f ".planning/OMM-REPORT.md" ]; then
|
|
115
|
+
OMM_RESILIENCE=$(grep -oE 'Capacidade 1.*Resilience.*[0-9]/5' .planning/OMM-REPORT.md | grep -oE '[0-9]/5' | head -1 | sed 's|/5||')
|
|
116
|
+
if [ -n "$OMM_RESILIENCE" ] && [ "$OMM_RESILIENCE" -ge 3 ]; then
|
|
117
|
+
MODE="blocking"
|
|
118
|
+
else
|
|
119
|
+
MODE="consultive"
|
|
120
|
+
fi
|
|
121
|
+
fi
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
[ -z "$MODE" ] && MODE="${CONFIG_MODE:-blocking}"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 3. Dispatch para `refactor-safety-auditor`
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
Task(
|
|
131
|
+
subagent_type="refactor-safety-auditor",
|
|
132
|
+
prompt="
|
|
133
|
+
target_file: ${TARGET_FILE}
|
|
134
|
+
change_kind: ${CHANGE_KIND}
|
|
135
|
+
output_path: ${OUTPUT_PATH}
|
|
136
|
+
mode: ${MODE}
|
|
137
|
+
${TICKET:+ticket: ${TICKET}}
|
|
138
|
+
${REASON:+reason: ${REASON}}
|
|
139
|
+
|
|
140
|
+
Aplicar skill pre-refactor-characterization. Etapas:
|
|
141
|
+
1. Preflight: detectar linguagem, validar input
|
|
142
|
+
2. Coletar evidências:
|
|
143
|
+
- line count + heurística de aninhamento
|
|
144
|
+
- external contract (path patterns, content markers, cross-package refs)
|
|
145
|
+
- coverage atual (line coverage como proxy)
|
|
146
|
+
- characterization tests existentes
|
|
147
|
+
- mutation kill score (se disponível)
|
|
148
|
+
3. Aplicar matriz de decisão (3 critérios canônicos)
|
|
149
|
+
4. Determinar caminho recomendado (caracterizar/sprout/safe-extract/override)
|
|
150
|
+
5. Escrever REFACTOR-SAFETY.md com evidências, veredito, paths, audit trail
|
|
151
|
+
6. Output curto para caller (veredito + custo + próximos passos)
|
|
152
|
+
"
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 4. Pós-output
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
═══════════════════════════════════════════════════════════
|
|
160
|
+
framework ► AUDITAR-REFACTOR ▸ ${OUTPUT_PATH}
|
|
161
|
+
═══════════════════════════════════════════════════════════
|
|
162
|
+
|
|
163
|
+
[output do refactor-safety-auditor]
|
|
164
|
+
|
|
165
|
+
## Decision matrix referência
|
|
166
|
+
|
|
167
|
+
| Veredito | Significado | Próxima ação |
|
|
168
|
+
|---|---|---|
|
|
169
|
+
| **GO** | Safety net adequado | Refactor pode prosseguir |
|
|
170
|
+
| **GO-OVERRIDE** | Bypass com audit trail | Refactor pode prosseguir, débito documentado em ticket |
|
|
171
|
+
| **WARN** | Risco médio | Considere `/caracterizar --gap-fill` antes; ou prosseguir + monitor |
|
|
172
|
+
| **BLOCK** | Risco alto sem safety net | Escolha um dos 4 caminhos abaixo |
|
|
173
|
+
|
|
174
|
+
## Caminhos quando BLOCK (em ordem de preferência)
|
|
175
|
+
|
|
176
|
+
1. **Caracterizar primeiro** (recomendado para refactor real)
|
|
177
|
+
```
|
|
178
|
+
/caracterizar <file>
|
|
179
|
+
```
|
|
180
|
+
Custo: 8-16h. Cobertura behavioral ≥ 70%. Gate retorna GO após.
|
|
181
|
+
|
|
182
|
+
2. **Sprout/Wrap** (não toca legado, ADICIONA comportamento)
|
|
183
|
+
```
|
|
184
|
+
/refactor-seguro --mode=sprout <file>
|
|
185
|
+
```
|
|
186
|
+
Custo: 0.5-4h. Legado intocado, novo testado isolado.
|
|
187
|
+
|
|
188
|
+
3. **Safe extraction** (mecânico — rename, IDE-extract)
|
|
189
|
+
```
|
|
190
|
+
/refactor-seguro --mode=safe-extract <file>
|
|
191
|
+
```
|
|
192
|
+
Custo: 1-2h. Apenas refactor sem mudança comportamental.
|
|
193
|
+
|
|
194
|
+
4. **Override** (último recurso, audit trail)
|
|
195
|
+
```
|
|
196
|
+
/refactor-seguro --mode=override --ticket REQ-N --reason "<texto>" <file>
|
|
197
|
+
```
|
|
198
|
+
Custo: 0h refactor + custo do débito. Aprovação humana obrigatória.
|
|
199
|
+
|
|
200
|
+
## Cross-suite
|
|
201
|
+
|
|
202
|
+
- **/instrumentar-fase** (v1.9) — durante refactor com BLOCK→GO via override, instrumentar para detecção precoce de regressão via golden signals
|
|
203
|
+
- **/burn-rate-status** (v1.9) — refactor pode regredir SLO; monitor budget pós-deploy
|
|
204
|
+
- **/prr** (v1.10) — Production Readiness Review Axe 5 (Change Management) consume veredito deste gate
|
|
205
|
+
- **/postmortem** (v1.10) — postmortems de regression em refactor sem char referenciam essa auditoria como lesson learned
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
</process>
|
|
209
|
+
|
|
210
|
+
<success_criteria>
|
|
211
|
+
- [ ] $ARGUMENTS parseados (target_file obrigatório, --change-kind=override exige ticket + reason)
|
|
212
|
+
- [ ] Mode resolvido: argument explícito > config.json > omm-auditor (Capacidade 1) > default blocking
|
|
213
|
+
- [ ] `refactor-safety-auditor` invocado via `Task(subagent_type=...)` com prompt completo (6 etapas)
|
|
214
|
+
- [ ] `.planning/REFACTOR-SAFETY.md` criado pelo agent
|
|
215
|
+
- [ ] Output forwarded transparentemente
|
|
216
|
+
- [ ] Decision matrix exibida para referência
|
|
217
|
+
- [ ] 4 caminhos oferecidos quando BLOCK (com comandos prontos para copy-paste)
|
|
218
|
+
- [ ] Cross-references com Suíte Observabilidade + SRE
|
|
219
|
+
</success_criteria>
|