@fullchico/harness 0.0.0-stage → 0.1.3

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.
Files changed (83) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/LICENSE +21 -0
  3. package/README.md +243 -2
  4. package/bin/harness.js +21 -0
  5. package/install +108 -0
  6. package/package.json +27 -4
  7. package/plugin/.claude-plugin/plugin.json +9 -0
  8. package/plugin/agents/implementador.md +55 -0
  9. package/plugin/agents/orquestrador.md +59 -0
  10. package/plugin/agents/qualidade.md +44 -0
  11. package/plugin/agents/revisor-ambiente.md +86 -0
  12. package/plugin/agents/revisor-bugs.md +153 -0
  13. package/plugin/agents/revisor-spec.md +49 -0
  14. package/plugin/agents/revisor.md +96 -0
  15. package/plugin/agents/seguranca.md +62 -0
  16. package/plugin/bin/sync +322 -0
  17. package/plugin/map.json +387 -0
  18. package/plugin/payload/agents-clean +77 -0
  19. package/plugin/payload/approve +34 -0
  20. package/plugin/payload/arch_check.py +94 -0
  21. package/plugin/payload/compose_check.py +186 -0
  22. package/plugin/payload/conf-apply +22 -0
  23. package/plugin/payload/destroy +21 -0
  24. package/plugin/payload/dev +24 -0
  25. package/plugin/payload/down +20 -0
  26. package/plugin/payload/entrega/despacho.md +186 -0
  27. package/plugin/payload/entrega/fechamento.md +179 -0
  28. package/plugin/payload/entrega/tickets.md +154 -0
  29. package/plugin/payload/env-common.sh +64 -0
  30. package/plugin/payload/fetch +10 -0
  31. package/plugin/payload/gate-check +159 -0
  32. package/plugin/payload/git-hooks/commit-msg +32 -0
  33. package/plugin/payload/git-hooks/pre-commit +19 -0
  34. package/plugin/payload/git-hooks/pre-push +15 -0
  35. package/plugin/payload/hooks/__pycache__/common.cpython-313.pyc +0 -0
  36. package/plugin/payload/hooks/__pycache__/gate_stamp.cpython-313.pyc +0 -0
  37. package/plugin/payload/hooks/common.py +274 -0
  38. package/plugin/payload/hooks/dispatch_guard.py +290 -0
  39. package/plugin/payload/hooks/gate_stamp.py +242 -0
  40. package/plugin/payload/hooks/managed_guard.py +95 -0
  41. package/plugin/payload/hooks/service_guard.py +178 -0
  42. package/plugin/payload/hooks/session_context.py +68 -0
  43. package/plugin/payload/hooks/subagent_context.py +49 -0
  44. package/plugin/payload/integrate +110 -0
  45. package/plugin/payload/learn +7 -0
  46. package/plugin/payload/learn.py +282 -0
  47. package/plugin/payload/manifest_check.py +68 -0
  48. package/plugin/payload/memory +7 -0
  49. package/plugin/payload/memory.py +521 -0
  50. package/plugin/payload/pendings +7 -0
  51. package/plugin/payload/ports-free +55 -0
  52. package/plugin/payload/pr +52 -0
  53. package/plugin/payload/prepare +10 -0
  54. package/plugin/payload/push +44 -0
  55. package/plugin/payload/setup-worktree +61 -0
  56. package/plugin/payload/skills-add +20 -0
  57. package/plugin/payload/skills-search +6 -0
  58. package/plugin/payload/skills-show +6 -0
  59. package/plugin/payload/skills_remote.py +111 -0
  60. package/plugin/payload/subagent-rules.md +14 -0
  61. package/plugin/payload/ticket +67 -0
  62. package/plugin/payload/tickets_check.py +206 -0
  63. package/plugin/payload/up +45 -0
  64. package/plugin/payload/update +45 -0
  65. package/plugin/payload/validate +90 -0
  66. package/plugin/payload/worktree-env +128 -0
  67. package/plugin/skills/aprender/SKILL.md +62 -0
  68. package/plugin/skills/buscar-skills/SKILL.md +73 -0
  69. package/plugin/skills/dream/SKILL.md +92 -0
  70. package/plugin/skills/entregar/SKILL.md +110 -0
  71. package/plugin/skills/entregar/references/spec.md +84 -0
  72. package/plugin/skills/mapear/SKILL.md +85 -0
  73. package/plugin/skills/setup/SKILL.md +66 -0
  74. package/plugin/templates/AGENTS.managed.md +173 -0
  75. package/plugin/templates/AGENTS.project.md +3 -0
  76. package/plugin/templates/CLAUDE.md +10 -0
  77. package/plugin/templates/conductor.toml +16 -0
  78. package/plugin/templates/docs/agents/domain.md +15 -0
  79. package/plugin/templates/docs/agents/issue-tracker.md +23 -0
  80. package/plugin/templates/docs/agents/stack.md +132 -0
  81. package/plugin/templates/harness.conf +61 -0
  82. package/plugin/templates/orca.yaml +10 -0
  83. package/plugin/templates/settings.json +210 -0
@@ -0,0 +1,387 @@
1
+ {
2
+ "spec_glob": "docs/specs/*/spec.md",
3
+ "tickets_glob": "docs/specs/*/issues/*.md",
4
+ "sources": {
5
+ "mattpocock-skills": {
6
+ "plugin": "mattpocock-skills@claude-plugins-official",
7
+ "ref": "1.3.1"
8
+ },
9
+ "ponytail": {
10
+ "plugin": "ponytail@ponytail",
11
+ "marketplace": {
12
+ "source": "github",
13
+ "repo": "DietrichGebert/ponytail"
14
+ },
15
+ "ref": "4.8.4"
16
+ },
17
+ "rtk": {
18
+ "binary": "rtk",
19
+ "hook": "rtk hook claude"
20
+ },
21
+ "frontend-design": {
22
+ "plugin": "frontend-design@claude-plugins-official"
23
+ }
24
+ },
25
+ "steps": [
26
+ {
27
+ "step": "entrevistar",
28
+ "skill": "grilling",
29
+ "source": "mattpocock-skills",
30
+ "adaptation": "nenhuma"
31
+ },
32
+ {
33
+ "step": "entrevistar",
34
+ "skill": "domain-modeling",
35
+ "source": "mattpocock-skills",
36
+ "adaptation": "docs/agents/domain.md gerado: glossário e ADRs"
37
+ },
38
+ {
39
+ "step": "implementar",
40
+ "skill": "tdd",
41
+ "source": "mattpocock-skills",
42
+ "adaptation": "instrução: testes nos pontos de costura da spec"
43
+ },
44
+ {
45
+ "step": "bug",
46
+ "skill": "diagnosing-bugs",
47
+ "source": "mattpocock-skills",
48
+ "adaptation": "nenhuma"
49
+ },
50
+ {
51
+ "step": "abrir-pr",
52
+ "skill": "pr",
53
+ "source": "mattpocock-skills",
54
+ "adaptation": "instrução: corpo em português, sem assinatura de IA"
55
+ },
56
+ {
57
+ "step": "sempre-ligado",
58
+ "skill": "ponytail",
59
+ "source": "ponytail",
60
+ "adaptation": "nenhuma"
61
+ },
62
+ {
63
+ "step": "sempre-ligado",
64
+ "skill": "rtk",
65
+ "source": "rtk",
66
+ "adaptation": "hook no settings.json gerado"
67
+ },
68
+ {
69
+ "step": "avulsa",
70
+ "skill": "code-review",
71
+ "source": "mattpocock-skills",
72
+ "adaptation": "nenhuma"
73
+ },
74
+ {
75
+ "step": "avulsa",
76
+ "skill": "prototype",
77
+ "source": "mattpocock-skills",
78
+ "adaptation": "nenhuma"
79
+ },
80
+ {
81
+ "step": "avulsa",
82
+ "skill": "research",
83
+ "source": "mattpocock-skills",
84
+ "adaptation": "nenhuma"
85
+ },
86
+ {
87
+ "step": "avulsa",
88
+ "skill": "codebase-design",
89
+ "source": "mattpocock-skills",
90
+ "adaptation": "nenhuma"
91
+ },
92
+ {
93
+ "step": "avulsa-dono",
94
+ "skill": "grill-with-docs",
95
+ "source": "mattpocock-skills",
96
+ "adaptation": "nenhuma"
97
+ },
98
+ {
99
+ "step": "avulsa-dono",
100
+ "skill": "to-spec",
101
+ "source": "mattpocock-skills",
102
+ "adaptation": "nenhuma"
103
+ },
104
+ {
105
+ "step": "avulsa-dono",
106
+ "skill": "to-tickets",
107
+ "source": "mattpocock-skills",
108
+ "adaptation": "nenhuma"
109
+ },
110
+ {
111
+ "step": "avulsa-dono",
112
+ "skill": "implement-spec",
113
+ "source": "mattpocock-skills",
114
+ "adaptation": "nenhuma"
115
+ },
116
+ {
117
+ "step": "avulsa-dono",
118
+ "skill": "retro",
119
+ "source": "mattpocock-skills",
120
+ "adaptation": "nenhuma"
121
+ },
122
+ {
123
+ "step": "avulsa-dono",
124
+ "skill": "wayfinder",
125
+ "source": "mattpocock-skills",
126
+ "adaptation": "nenhuma"
127
+ },
128
+ {
129
+ "step": "avulsa-dono",
130
+ "skill": "handoff",
131
+ "source": "mattpocock-skills",
132
+ "adaptation": "nenhuma"
133
+ },
134
+ {
135
+ "step": "fatiar",
136
+ "skill": "parallel-feature-development",
137
+ "source": "project_skills",
138
+ "adaptation": "ver project_skills"
139
+ },
140
+ {
141
+ "step": "implementar",
142
+ "skill": "hexagonal-architecture",
143
+ "source": "project_skills",
144
+ "adaptation": "ver project_skills"
145
+ },
146
+ {
147
+ "step": "implementar",
148
+ "skill": "feature-sliced-design",
149
+ "source": "project_skills",
150
+ "adaptation": "ver project_skills"
151
+ },
152
+ {
153
+ "step": "revisar",
154
+ "skill": "clean-code-guard",
155
+ "source": "project_skills",
156
+ "adaptation": "ver project_skills"
157
+ },
158
+ {
159
+ "step": "revisar",
160
+ "skill": "ponytail-review",
161
+ "source": "ponytail",
162
+ "adaptation": "critérios de duplicação e enxugamento"
163
+ },
164
+ {
165
+ "step": "implementar",
166
+ "skill": "frontend-design",
167
+ "source": "frontend-design",
168
+ "adaptation": "direção visual das telas"
169
+ }
170
+ ],
171
+ "project_skills": [
172
+ {
173
+ "skill": "hexagonal-architecture",
174
+ "repo": "affaan-m/ecc",
175
+ "role": "arquitetura do back: use case, portas, adaptadores, ponto único de montagem",
176
+ "adaptation": "porta só em fronteira de entrada e saída real; log e relógio não viram porta",
177
+ "profiles": [
178
+ "fullstack-typescript",
179
+ "livre"
180
+ ]
181
+ },
182
+ {
183
+ "skill": "feature-sliced-design",
184
+ "repo": "feature-sliced/skills",
185
+ "role": "arquitetura do front: camadas, fatias, entrada pública",
186
+ "adaptation": "o shared do front é camada interna; o contrato com o back é outro pacote (CONTRACT_PATHS)",
187
+ "profiles": [
188
+ "fullstack-typescript"
189
+ ]
190
+ },
191
+ {
192
+ "skill": "parallel-feature-development",
193
+ "repo": "wshobson/agents",
194
+ "role": "fatiar para trabalho paralelo: um dono por arquivo, contrato primeiro",
195
+ "adaptation": "quem é 'team-lead' é o orquestrador; implementador não troca mensagem, relata lacuna",
196
+ "profiles": [
197
+ "fullstack-typescript",
198
+ "livre",
199
+ "existente"
200
+ ]
201
+ },
202
+ {
203
+ "skill": "clean-code-guard",
204
+ "repo": "amelnagdy/guard-skills",
205
+ "role": "rubrica do revisor: nomes, funções, SOLID, DRY",
206
+ "adaptation": "só o revisor aplica; porta em fronteira de entrada e saída é convenção do projeto, não excesso",
207
+ "profiles": [
208
+ "fullstack-typescript",
209
+ "livre",
210
+ "existente"
211
+ ]
212
+ },
213
+ {
214
+ "skill": "vercel-react-best-practices",
215
+ "repo": "vercel-labs/agent-skills",
216
+ "role": "React e desempenho no front",
217
+ "who": "implementador de front",
218
+ "adaptation": "evitar arquivo de índice vale só para bibliotecas de terceiros; a fatia tem o seu",
219
+ "profiles": [
220
+ "fullstack-typescript"
221
+ ]
222
+ },
223
+ {
224
+ "skill": "shadcn",
225
+ "repo": "shadcn-ui/ui",
226
+ "role": "componentes de interface",
227
+ "who": "implementador de front",
228
+ "adaptation": "componentes vão para a camada shared do front, pelo components.json",
229
+ "profiles": [
230
+ "fullstack-typescript"
231
+ ]
232
+ },
233
+ {
234
+ "skill": "zod",
235
+ "repo": "anivar/zod-skill",
236
+ "role": "validação e contrato",
237
+ "who": "implementadores",
238
+ "adaptation": "os esquemas de contrato ficam no pacote comum, não por camada",
239
+ "profiles": [
240
+ "fullstack-typescript"
241
+ ]
242
+ },
243
+ {
244
+ "skill": "drizzle-orm-patterns",
245
+ "repo": "giuseppe-trisciuoglio/developer-kit",
246
+ "role": "acesso a banco",
247
+ "who": "implementador de back",
248
+ "adaptation": "só dentro de adaptadores; tipos inferidos do ORM não saem deles",
249
+ "profiles": [
250
+ "fullstack-typescript"
251
+ ]
252
+ },
253
+ {
254
+ "skill": "supabase-postgres-best-practices",
255
+ "repo": "supabase/agent-skills",
256
+ "role": "esquema e consultas no Postgres",
257
+ "who": "implementador de back",
258
+ "adaptation": "ignorar o que é específico do Supabase",
259
+ "profiles": [
260
+ "fullstack-typescript"
261
+ ]
262
+ },
263
+ {
264
+ "skill": "bullmq",
265
+ "repo": "jgamaraalv/ts-dev-kit",
266
+ "role": "filas",
267
+ "who": "implementador de back",
268
+ "adaptation": "fila e worker em adaptadores; pnpm no lugar de yarn",
269
+ "profiles": [
270
+ "fullstack-typescript"
271
+ ]
272
+ },
273
+ {
274
+ "skill": "vitest",
275
+ "repo": "antfu/skills",
276
+ "role": "testes de unidade e integração",
277
+ "who": "todos",
278
+ "adaptation": "conferir a versão instalada",
279
+ "profiles": [
280
+ "fullstack-typescript"
281
+ ]
282
+ },
283
+ {
284
+ "skill": "pnpm",
285
+ "repo": "antfu/skills",
286
+ "role": "monorepo e dependências",
287
+ "who": "ticket de contrato",
288
+ "adaptation": "conferir a versão instalada",
289
+ "profiles": [
290
+ "fullstack-typescript"
291
+ ]
292
+ },
293
+ {
294
+ "skill": "seo",
295
+ "repo": "addyosmani/web-quality-skills",
296
+ "role": "SEO técnico",
297
+ "who": "ticket de contrato e páginas públicas",
298
+ "adaptation": "usar a API de metadados do Next no lugar do HTML dos exemplos",
299
+ "profiles": [
300
+ "fullstack-typescript"
301
+ ]
302
+ },
303
+ {
304
+ "skill": "accessibility",
305
+ "repo": "addyosmani/web-quality-skills",
306
+ "role": "acessibilidade",
307
+ "who": "revisor de código",
308
+ "adaptation": "sem instalar ferramenta global",
309
+ "profiles": [
310
+ "fullstack-typescript"
311
+ ]
312
+ },
313
+ {
314
+ "skill": "owasp-security",
315
+ "repo": "agamm/claude-code-owasp",
316
+ "role": "revisão de segurança",
317
+ "who": "revisor de segurança",
318
+ "adaptation": "só como lista do que procurar",
319
+ "profiles": [
320
+ "fullstack-typescript"
321
+ ]
322
+ },
323
+ {
324
+ "skill": "playwright-best-practices",
325
+ "repo": "currents-dev/playwright-best-practices-skill",
326
+ "role": "testes de ponta a ponta",
327
+ "who": "ticket de ponta a ponta",
328
+ "adaptation": "sem page object por padrão; o navegador roda no contêiner do ambiente",
329
+ "profiles": [
330
+ "fullstack-typescript"
331
+ ]
332
+ },
333
+ {
334
+ "skill": "nestjs-best-practices",
335
+ "repo": "kadajett/agent-nestjs-skills",
336
+ "role": "NestJS: módulos, injeção, erros, testes",
337
+ "who": "módulo do back",
338
+ "adaptation": "validação de entrada é pelo Zod do contrato, não class-validator; regra de negócio fica no use case, não em service; ignore microsserviços e deploy",
339
+ "profiles": [
340
+ "fullstack-typescript"
341
+ ]
342
+ },
343
+ {
344
+ "skill": "nextjs-app-router-patterns",
345
+ "repo": "wshobson/agents",
346
+ "role": "Next.js: App Router, componentes de servidor e de cliente",
347
+ "who": "fatia do front",
348
+ "adaptation": "o Next só apresenta: nada de regra de negócio nem banco em rota ou server action; os dados vêm da API do back",
349
+ "profiles": [
350
+ "fullstack-typescript"
351
+ ]
352
+ },
353
+ {
354
+ "skill": "property-based-testing",
355
+ "repo": "trailofbits/skills",
356
+ "role": "teste por propriedade em regra com borda (data, dinheiro, intervalo)",
357
+ "who": "módulo do back e caçador de bugs",
358
+ "adaptation": "só com fast-check e só onde a regra tem borda; não é para todo teste",
359
+ "profiles": [
360
+ "fullstack-typescript"
361
+ ]
362
+ },
363
+ {
364
+ "skill": "write-pr-description",
365
+ "repo": "warpdotdev/common-skills",
366
+ "role": "texto do pull request",
367
+ "who": "quem fecha a entrega",
368
+ "adaptation": "o padrão de seções é o do roteiro de fechamento; a skill só melhora o texto",
369
+ "profiles": [
370
+ "fullstack-typescript"
371
+ ]
372
+ }
373
+ ],
374
+ "stack": {
375
+ "name": "fullstack-typescript",
376
+ "back": "NestJS, Drizzle, Postgres, BullMQ sobre Redis",
377
+ "front": "Next.js (App Router), shadcn, Tailwind",
378
+ "contrato": "Zod, num pacote comum",
379
+ "testes": "Vitest e Playwright",
380
+ "monorepo": "pnpm"
381
+ },
382
+ "profiles": {
383
+ "fullstack-typescript": "stack padrão: arquitetura, stack e skills da stack",
384
+ "livre": "projeto novo em outra stack: conceitos de arquitetura, sem stack",
385
+ "existente": "projeto que já tinha código: processo e proteção, sem impor arquitetura nem língua"
386
+ }
387
+ }
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env bash
2
+ # Remove os worktrees de agente cujo trabalho já foi integrado na branch atual, e as
3
+ # branches deles. O que ainda não foi integrado, ou está em uso, fica e é listado.
4
+ # Uso: .harness/agents-clean
5
+ # .harness/agents-clean --superseded depois do envio: o que saiu desta feature e não entrou
6
+ # .harness/agents-clean --discard <branch> joga fora o worktree de agente dessa branch,
7
+ # mesmo sem integrar (trabalho recusado e refeito)
8
+ set -uo pipefail
9
+
10
+ ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || { echo "agents-clean: fora de um repositório git." >&2; exit 2; }
11
+ cd "$ROOT" || exit 1
12
+
13
+ if [ "${1:-}" = "--discard" ]; then
14
+ TARGET="${2:-}"
15
+ FOUND="$(git worktree list --porcelain | awk -v b="refs/heads/$TARGET" '/^worktree /{p=substr($0,10)} $0=="branch " b {print p}')"
16
+ case "$FOUND" in
17
+ */.claude/worktrees/*) ;;
18
+ *) echo "agents-clean: $TARGET não é a branch de um worktree de agente." >&2; exit 1 ;;
19
+ esac
20
+ git worktree remove --force "$FOUND" && git branch -q -D "$TARGET" && echo "descartado: $FOUND"
21
+ exit $?
22
+ fi
23
+
24
+ if [ "${1:-}" = "--superseded" ]; then
25
+ # Depois do envio: worktrees de agente que saíram desta feature e não entraram nela (tentativa
26
+ # recusada e refeita). Os de outra feature, que saíram da branch padrão, não são tocados.
27
+ HERE="$(cd "$(dirname "$0")" && pwd -P)"
28
+ BASE="$(python3 -I "$HERE/hooks/common.py" branch-base "$(git rev-parse HEAD)" 2>/dev/null)" || BASE=""
29
+ [ -n "$BASE" ] || exit 0
30
+ git worktree list --porcelain | awk '/^worktree /{p=substr($0,10)} /^HEAD /{h=$2} /^branch /{b=substr($0,19)} /^locked/{l=1} /^$/{if(p!="")print p"\t"h"\t"b"\t"l; p="";h="";b="";l=""} END{if(p!="")print p"\t"h"\t"b"\t"l}' \
31
+ | while IFS="$(printf '\t')" read -r P H B L; do
32
+ case "$P" in */.claude/worktrees/*) ;; *) continue ;; esac
33
+ [ -z "$L" ] || continue
34
+ MB="$(git merge-base "$H" HEAD 2>/dev/null)" || continue
35
+ [ "$MB" != "$BASE" ] && git merge-base --is-ancestor "$BASE" "$MB" 2>/dev/null || continue
36
+ git worktree remove --force "$P" 2>/dev/null && { [ -n "$B" ] && git branch -q -D "$B" 2>/dev/null; echo "descartado: $P"; }
37
+ done
38
+ git worktree prune
39
+ exit 0
40
+ fi
41
+
42
+ PATH_="" HEAD_="" BRANCH="" LOCKED=""
43
+ finish() {
44
+ [ -n "$PATH_" ] || return 0
45
+ case "$PATH_" in
46
+ */.claude/worktrees/*)
47
+ if [ -n "$LOCKED" ]; then
48
+ echo "fica (em uso): $PATH_"
49
+ elif [ -n "$(git -C "$PATH_" status --porcelain 2>/dev/null | head -n 1)" ]; then
50
+ echo "fica (alteração sem commit): $PATH_"
51
+ elif [ -n "$HEAD_" ] && git merge-base --is-ancestor "$HEAD_" HEAD 2>/dev/null; then
52
+ if git worktree remove --force "$PATH_" 2>/dev/null; then
53
+ [ -n "$BRANCH" ] && git branch -q -D "$BRANCH" 2>/dev/null
54
+ echo "removido: $PATH_"
55
+ else
56
+ echo "não consegui remover: $PATH_" >&2
57
+ fi
58
+ else
59
+ echo "fica (não integrado em $(git branch --show-current)): $PATH_"
60
+ fi ;;
61
+ esac
62
+ PATH_="" HEAD_="" BRANCH="" LOCKED=""
63
+ }
64
+
65
+ while IFS= read -r LINE; do
66
+ case "$LINE" in
67
+ "worktree "*) finish; PATH_="${LINE#worktree }" ;;
68
+ "HEAD "*) HEAD_="${LINE#HEAD }" ;;
69
+ "branch refs/heads/"*) BRANCH="${LINE#branch refs/heads/}" ;;
70
+ locked*) LOCKED=1 ;;
71
+ esac
72
+ done <<EOT
73
+ $(git worktree list --porcelain)
74
+ EOT
75
+ finish
76
+ git worktree prune
77
+ exit 0
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env bash
2
+ # Carimbo manual do dono para um portão de push, sobre o commit atual.
3
+ # Uso: .harness/approve <seguranca|revisao|qualidade|bugs|ambiente> "<resumo do que foi revisado>"
4
+ # Agentes são negados pelo sandbox e pela exigência de terminal: quem revisa com IA não carimba.
5
+ set -euo pipefail
6
+
7
+ GATE="${1:-}"
8
+ RESUMO="${2:-}"
9
+
10
+ usage() { echo 'uso: approve <seguranca|revisao|qualidade|bugs|ambiente> "<resumo>"' >&2; exit 1; }
11
+
12
+ # Sem terminal na entrada, quem está chamando não é o dono digitando.
13
+ [ -t 0 ] || { echo "approve: só roda num terminal, pelo dono. Agentes não carimbam aprovação." >&2; exit 1; }
14
+
15
+ case "$GATE" in seguranca|revisao|qualidade|bugs|ambiente) ;; *) usage ;; esac
16
+ [ -n "${RESUMO//[[:space:]]/}" ] || usage
17
+
18
+ HERE="$(cd "$(dirname "$0")" && pwd -P)"
19
+ STATE="$(python3 -I "$HERE/hooks/common.py" state-dir 2>/dev/null)" || {
20
+ echo "erro: fora de um repositório git" >&2; exit 1; }
21
+ SHA="$(git rev-parse HEAD 2>/dev/null)" || { echo "erro: repositório sem commit" >&2; exit 1; }
22
+
23
+ DIR="$STATE/approvals/$GATE"
24
+ mkdir -p "$DIR"
25
+ python3 -I - "$DIR/$SHA.json" "$GATE" "$SHA" "$RESUMO" <<'PY'
26
+ import datetime, json, sys
27
+ path, gate, sha, resumo = sys.argv[1:5]
28
+ record = {"gate": gate, "sha": sha, "base": None, "status": "PASS", "resumo": resumo, "by": "owner",
29
+ "agent_type": None, "transcript": None,
30
+ "timestamp": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")}
31
+ with open(path, "w", encoding="utf-8") as f:
32
+ json.dump(record, f, ensure_ascii=False, indent=2)
33
+ PY
34
+ echo "[$GATE] aprovado pelo dono para o commit $SHA"
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env python3
2
+ """Fronteira entre módulos, por lista branca.
3
+
4
+ Uso: arch_check.py <raiz do projeto>
5
+
6
+ Lê MODULE_ROOTS e CONTRACT_PATHS do harness.conf. Cada pasta logo abaixo de uma raiz de
7
+ módulos é um módulo. Arquivo de um módulo só importa de dentro do próprio módulo, do que é
8
+ comum (CONTRACT_PATHS), de pacotes e da entrada pública (index) de outro módulo. Todo o resto é recusado: importação de tipo, reexportação,
9
+ require e import dinâmico contam igual.
10
+ """
11
+ import os
12
+ import re
13
+ import sys
14
+
15
+ sys.dont_write_bytecode = True
16
+ sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "hooks"))
17
+ import common # noqa: E402
18
+
19
+ SOURCES = (".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs")
20
+ # ponytail: casa por texto, então um import dentro de comentário também conta. Trocar por
21
+ # um analisador da linguagem se isso der falso positivo de verdade.
22
+ SPECIFIER = re.compile(r"""(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)["']([^"']+)["']""")
23
+
24
+
25
+ INSIDE = ('entra por dentro do módulo "{other}" ({specifier}). De outro módulo só se importa a entrada '
26
+ "pública dele (o index); o que ele não exporta ali não é para uso de fora.")
27
+
28
+
29
+ def _is_entry(rest: list) -> bool:
30
+ """O que sobra do caminho depois do nome do módulo: nada, ou o index dele."""
31
+ return not rest or (len(rest) == 1 and rest[0].split(".")[0] == "index")
32
+
33
+
34
+ def _inside(path: str, folder: str) -> bool:
35
+ return path == folder or path.startswith(folder + os.sep)
36
+
37
+
38
+ def violations(root: str) -> list:
39
+ conf = common.read_conf(os.path.join(root, "harness.conf"))
40
+ module_roots = [os.path.normpath(os.path.join(root, p)) for p in conf.get("MODULE_ROOTS", "").split()]
41
+ shared = [os.path.normpath(os.path.join(root, p)) for p in conf.get("CONTRACT_PATHS", "").split()]
42
+ found = []
43
+ for modules_dir in module_roots:
44
+ if not os.path.isdir(modules_dir):
45
+ continue
46
+ names = sorted(n for n in os.listdir(modules_dir) if os.path.isdir(os.path.join(modules_dir, n)))
47
+ for name in names:
48
+ own = os.path.join(modules_dir, name)
49
+ others = [n for n in names if n != name]
50
+ for folder, dirs, files in os.walk(own):
51
+ dirs[:] = [d for d in dirs if d != "node_modules"]
52
+ for file in files:
53
+ if not file.endswith(SOURCES):
54
+ continue
55
+ path = os.path.join(folder, file)
56
+ with open(path, encoding="utf-8", errors="replace") as f:
57
+ text = f.read()
58
+ for match in SPECIFIER.finditer(text):
59
+ reason = _reason(match.group(1), folder, own, modules_dir, others, shared)
60
+ if reason:
61
+ line = text.count("\n", 0, match.start()) + 1
62
+ found.append(f"{os.path.relpath(path, root)}:{line}: {reason}")
63
+ return found
64
+
65
+
66
+ def _reason(specifier, folder, own, modules_dir, others, shared):
67
+ if specifier.startswith("."):
68
+ target = os.path.normpath(os.path.join(folder, specifier))
69
+ if _inside(target, own) or any(_inside(target, s) for s in shared):
70
+ return ""
71
+ if _inside(target, modules_dir):
72
+ parts = os.path.relpath(target, modules_dir).split(os.sep)
73
+ return "" if _is_entry(parts[1:]) else INSIDE.format(other=parts[0], specifier=specifier)
74
+ return f"importa de fora do módulo e fora do que é comum ({specifier}). O que mais de um módulo usa fica num caminho de CONTRACT_PATHS."
75
+ marker = os.path.basename(modules_dir) + "/"
76
+ for other in others:
77
+ head, found, rest = (specifier + "/").partition(marker + other + "/")
78
+ if found and not _is_entry([p for p in rest.split("/") if p]):
79
+ return INSIDE.format(other=other, specifier=specifier)
80
+ return ""
81
+
82
+
83
+ def main() -> int:
84
+ if len(sys.argv) != 2:
85
+ print("uso: arch_check.py <raiz do projeto>", file=sys.stderr)
86
+ return 2
87
+ found = violations(os.path.realpath(sys.argv[1]))
88
+ for line in found:
89
+ print(line, file=sys.stderr)
90
+ return 1 if found else 0
91
+
92
+
93
+ if __name__ == "__main__":
94
+ sys.exit(main())