teqo-backup/.agents/hooks/guard-env-files.mjs
Francisco Ignácio Fontoura Solla a2fbcb9c00 chore(agents): reorganiza árvore de skills — .claude/.cursor → .agents
- Remove .claude/skills (symlinks) e a árvore .cursor (rules, hooks, skills)
- Adiciona .agents/ com skills (+ references/), rules/, hooks/ e scripts
- Adiciona .codex/hooks.json (hook do impeccable)
- Corrige referências .cursor → .agents em environment.json, hooks.json e AGENTS.md
2026-08-03 21:24:11 -03:00

37 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Portable write guard (repo hooks.json, preToolUse on Write/Edit).
*
* Denies agent writes to local env files (`.env`, `.env.local`, `.env.test`):
* they carry DATABASE_URLs and secrets, and the parallel-ops contract says
* agents never repoint databases (stage/prod URLs live only in CI secrets and
* human-run scripts). Humans editing by hand are unaffected — this only gates
* tool calls.
*
* Contract (same as the impeccable hook): never break a turn accidentally —
* malformed input or internal errors allow the tool and exit 0.
*/
const DENY_PATTERN = /(^|\/)\.env(\.local|\.test|\.production)?$/
let input = ''
process.stdin.on('data', (chunk) => (input += chunk))
process.stdin.on('end', () => {
try {
const payload = JSON.parse(input)
const filePath = payload?.tool_input?.file_path ?? payload?.tool_input?.path ?? ''
if (typeof filePath === 'string' && DENY_PATTERN.test(filePath)) {
process.stdout.write(
JSON.stringify({
decision: 'deny',
reason:
'Agentes não editam arquivos .env* (contrato agentic ops: nunca repontar DATABASE_URL; stage/prod só em secrets de CI e scripts humanos).',
}),
)
process.exit(0)
}
} catch {
// malformed input → allow
}
process.exit(0)
})