@fontdata/ai-harness 4.6.0 → 4.7.1
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/.claude-plugin/plugin.json +2 -2
- package/README.md +8 -0
- package/dist/cli.js +7 -0
- package/dist/config/config.js +47 -5
- package/dist/doctor/checks.js +2 -0
- package/dist/doctor/seguranca.js +101 -0
- package/dist/init.js +1 -1
- package/dist/install/plan.js +16 -3
- package/dist/install/settings.js +83 -13
- package/dist/seguranca/checar-comando.js +90 -0
- package/dist/update/update.js +28 -14
- package/package.json +1 -1
- package/templates/hooks/arquivo-sensivel.mjs +83 -0
- package/templates/hooks/comando-destrutivo.mjs +74 -0
- package/templates/hooks/hooks.json +9 -2
- package/templates/hooks/lib/comando-texto.mjs +386 -0
- package/templates/hooks/lib/config.mjs +43 -0
- package/templates/hooks/lib/hook.mjs +22 -12
- package/templates/hooks/lib/regras/apagar.mjs +100 -0
- package/templates/hooks/lib/regras/git.mjs +131 -0
- package/templates/hooks/lib/regras/remoto.mjs +228 -0
- package/templates/hooks/lib/regras/sql.mjs +63 -0
- package/templates/hooks/lib/segredos.mjs +1 -1
- package/templates/rules/seguranca-harness.md +83 -0
- package/templates/skills/evoluir-harness/references/rule.md +3 -0
package/dist/update/update.js
CHANGED
|
@@ -8,10 +8,10 @@ import { suggestFlag } from '../install/flags.js';
|
|
|
8
8
|
import { HOOKS_ITEM_ID, isHarnessPluginEnabled, projectHooksConfig } from '../install/hooks.js';
|
|
9
9
|
import { BANCO_MCP_NOME, BANCO_MCP_NOME_LEGADO, bancoMcpServer, ehEntradaGerenciada, MCP_PATH, mergeMcpServers } from '../install/mcp.js';
|
|
10
10
|
import { hashContent, LOCK_PATH, LOCK_VERSION, readLock, writeLock } from '../install/lock.js';
|
|
11
|
-
import { agentsForaDoLock, itemSources, packageInfo, PROJECT_RULE_PATH, projectRuleContent } from '../install/plan.js';
|
|
11
|
+
import { agentsForaDoLock, itemSources, packageInfo, PROJECT_RULE_PATH, projectRuleContent, SECURITY_RULE_ID } from '../install/plan.js';
|
|
12
12
|
import { PERFIL_DELPHI_HOOK_COMMAND, perfilDelphiHooksConfig, perfilRecusadoNoConfig, PERFIS, perfisDoProjeto } from '../install/perfis.js';
|
|
13
13
|
import { neededSkillsFor } from '../install/selection.js';
|
|
14
|
-
import { BANCO_PERMISSIONS_LEGADAS, combineHooks,
|
|
14
|
+
import { BANCO_PERMISSIONS_LEGADAS, bypassDesligado, combineHooks, harnessDeny, harnessPermissions, hasAllowRule, hookCommands, hooksRegistrados, mergeSettings, normalizarComandoHook, SEGREDOS_DENY, SETTINGS_PATH, } from '../install/settings.js';
|
|
15
15
|
import { adoptLegacyInstall } from './legado.js';
|
|
16
16
|
const PERFIL_DELPHI_ITEM = 'perfil:delphi';
|
|
17
17
|
/** Pastas que os arquivos do item ocupam no projeto (`.claude/<tipo>/<nome>/`), as que ainda existem. */
|
|
@@ -41,7 +41,7 @@ function perfilDelphiRegistrado(root) {
|
|
|
41
41
|
const comando = normalizarComandoHook(PERFIL_DELPHI_HOOK_COMMAND);
|
|
42
42
|
return Object.keys(perfilDelphiHooksConfig()).every((evento) => hookCommands({ [evento]: hooks[evento] ?? [] }).map(normalizarComandoHook).includes(comando));
|
|
43
43
|
}
|
|
44
|
-
/** O settings do projeto já registra cada
|
|
44
|
+
/** O settings do projeto já registra cada hook do núcleo no evento dele, com o mesmo `command`, `matcher` e `if`. */
|
|
45
45
|
function hooksNucleoRegistrados(root) {
|
|
46
46
|
let hooks;
|
|
47
47
|
try {
|
|
@@ -50,13 +50,7 @@ function hooksNucleoRegistrados(root) {
|
|
|
50
50
|
catch {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
return false;
|
|
55
|
-
const registrados = hooks;
|
|
56
|
-
return Object.entries(projectHooksConfig()).every(([evento, grupos]) => {
|
|
57
|
-
const existentes = new Set(hookCommands({ [evento]: registrados[evento] ?? [] }).map(normalizarComandoHook));
|
|
58
|
-
return hookCommands({ [evento]: grupos }).every((comando) => existentes.has(normalizarComandoHook(comando)));
|
|
59
|
-
});
|
|
53
|
+
return hooksRegistrados(hooks, projectHooksConfig());
|
|
60
54
|
}
|
|
61
55
|
function isPlainObject(value) {
|
|
62
56
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -96,6 +90,7 @@ function legacyPath(root, path) {
|
|
|
96
90
|
return candidate;
|
|
97
91
|
}
|
|
98
92
|
}
|
|
93
|
+
const LEGACY_SECURITY_RULE = 'rule:seguranca';
|
|
99
94
|
export function checkUpdate(root, catalog = loadCatalog(), legacy, home, { semBanco = false, semComentarios = false } = {}) {
|
|
100
95
|
const recorded = readLock(root);
|
|
101
96
|
const lock = recorded ?? adoptLegacyInstall(root, legacy);
|
|
@@ -127,6 +122,8 @@ export function checkUpdate(root, catalog = loadCatalog(), legacy, home, { semBa
|
|
|
127
122
|
stale.push(entry.caminho);
|
|
128
123
|
else if (!localChanged)
|
|
129
124
|
changes.push({ tipo: 'removido', caminho: entry.caminho, item: key, source });
|
|
125
|
+
else if (key === LEGACY_SECURITY_RULE)
|
|
126
|
+
changes.push({ tipo: 'mantido', caminho: entry.caminho, item: key, source });
|
|
130
127
|
// Comando editado que saiu do pacote: renomeado, para não sombrear a skill de mesmo nome (D-35).
|
|
131
128
|
else if (item.tipo === 'comando') {
|
|
132
129
|
changes.push({ tipo: 'legado', caminho: entry.caminho, item: key, source, destino: legacyPath(root, entry.caminho) });
|
|
@@ -209,6 +206,8 @@ export function checkUpdate(root, catalog = loadCatalog(), legacy, home, { semBa
|
|
|
209
206
|
}
|
|
210
207
|
for (const id of agentsForaDoLock(catalog, lock))
|
|
211
208
|
addItem('agent', id, true);
|
|
209
|
+
if (trackedItems.has(`hook:${HOOKS_ITEM_ID}`) || isHarnessPluginEnabled(root, home))
|
|
210
|
+
addItem('rule', SECURITY_RULE_ID, true);
|
|
212
211
|
const registrarHooksNucleo = !adotada && lock.itens.some((item) => item.tipo === 'hook' && item.id === HOOKS_ITEM_ID) && !isHarnessPluginEnabled(root, home) && !hooksNucleoRegistrados(root);
|
|
213
212
|
// O padrão de comentários também chega ao lock anterior a ele, salvo com a recusa no config ou na flag. O hook é a
|
|
214
213
|
// referência: o comando `comentarios` não registra a rule quando o projeto já tem uma própria.
|
|
@@ -226,9 +225,14 @@ export function checkUpdate(root, catalog = loadCatalog(), legacy, home, { semBa
|
|
|
226
225
|
const registrarPerfilDelphi = instalarPerfis.includes('delphi') || (!!itemDoPerfil('delphi') && !recusados.has(PERFIL_DELPHI_ITEM) && !perfilDelphiRegistrado(root));
|
|
227
226
|
const registrarMcpConfig = config.banco_dados.registrar_mcp;
|
|
228
227
|
const permissoesBanco = !semBanco && registrarMcpConfig;
|
|
228
|
+
const seguranca = { negarLeituraSegredos: config.seguranca.negar_leitura_segredos, desligarBypass: config.seguranca.desligar_bypass };
|
|
229
229
|
const permissoesFaltando = [
|
|
230
230
|
...harnessPermissions({ banco: permissoesBanco }).filter((rule) => !hasAllowRule(root, rule)),
|
|
231
|
-
...
|
|
231
|
+
...harnessDeny({ negarLeituraSegredos: seguranca.negarLeituraSegredos })
|
|
232
|
+
.filter((rule) => !hasAllowRule(root, rule, 'deny'))
|
|
233
|
+
.map((rule) => `deny ${rule}`),
|
|
234
|
+
...(seguranca.negarLeituraSegredos ? [] : SEGREDOS_DENY.filter((rule) => hasAllowRule(root, rule, 'deny')).map((rule) => `remover deny ${rule}`)),
|
|
235
|
+
...(seguranca.desligarBypass && !bypassDesligado(root) ? ['disableBypassPermissionsMode "disable"'] : []),
|
|
232
236
|
];
|
|
233
237
|
const permissoesLegadas = BANCO_PERMISSIONS_LEGADAS.filter((rule) => hasAllowRule(root, rule));
|
|
234
238
|
const registrarMcp = !semBanco && registrarMcpConfig && !isHarnessPluginEnabled(root, home);
|
|
@@ -244,6 +248,7 @@ export function checkUpdate(root, catalog = loadCatalog(), legacy, home, { semBa
|
|
|
244
248
|
recusarComentarios: semComentarios && config.comentarios.instalar,
|
|
245
249
|
permissaoAusente: permissoesFaltando.length > 0,
|
|
246
250
|
permissoesFaltando,
|
|
251
|
+
seguranca,
|
|
247
252
|
permissoesLegadas,
|
|
248
253
|
permissoesBanco,
|
|
249
254
|
registrarMcp,
|
|
@@ -266,9 +271,15 @@ export function applyUpdate(root, report, options, pkg, now = new Date()) {
|
|
|
266
271
|
const remove = [];
|
|
267
272
|
const kept = [];
|
|
268
273
|
const legacy = [];
|
|
274
|
+
const unlinked = [];
|
|
269
275
|
for (const change of report.changes) {
|
|
270
276
|
if (change.tipo === 'modificado-local')
|
|
271
277
|
continue;
|
|
278
|
+
if (change.tipo === 'mantido') {
|
|
279
|
+
kept.push(change.caminho);
|
|
280
|
+
unlinked.push(change.caminho);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
272
283
|
if (change.tipo === 'legado') {
|
|
273
284
|
legacy.push(change.caminho);
|
|
274
285
|
continue;
|
|
@@ -295,8 +306,10 @@ export function applyUpdate(root, report, options, pkg, now = new Date()) {
|
|
|
295
306
|
const settings = mergeSettings(root, {
|
|
296
307
|
hooks,
|
|
297
308
|
allow: harnessPermissions({ banco: report.permissoesBanco }),
|
|
298
|
-
deny:
|
|
309
|
+
deny: harnessDeny({ negarLeituraSegredos: report.seguranca.negarLeituraSegredos }),
|
|
299
310
|
removeAllow: BANCO_PERMISSIONS_LEGADAS,
|
|
311
|
+
removeDeny: report.seguranca.negarLeituraSegredos ? [] : SEGREDOS_DENY,
|
|
312
|
+
disableBypass: report.seguranca.desligarBypass,
|
|
300
313
|
removeHooks: itensRecusados(report.perfisRecusados).has(PERFIL_DELPHI_ITEM) ? [PERFIL_DELPHI_HOOK_COMMAND] : [],
|
|
301
314
|
}, now);
|
|
302
315
|
if (settings.changed)
|
|
@@ -354,7 +367,7 @@ export function applyUpdate(root, report, options, pkg, now = new Date()) {
|
|
|
354
367
|
}
|
|
355
368
|
const itemOf = new Map(report.changes.map((change) => [change.caminho, change.item]));
|
|
356
369
|
const writtenHash = new Map(write.map((file) => [file.path, hashContent(file.content)]));
|
|
357
|
-
const dropped = new Set([...remove, ...report.stale, ...legacy]);
|
|
370
|
+
const dropped = new Set([...remove, ...report.stale, ...legacy, ...unlinked]);
|
|
358
371
|
const itens = [];
|
|
359
372
|
const recusados = itensRecusados(report.perfisRecusados);
|
|
360
373
|
for (const item of report.lock.itens) {
|
|
@@ -409,6 +422,7 @@ const DESCRIPTIONS = {
|
|
|
409
422
|
legado: 'editado localmente e saiu do pacote, será renomeado',
|
|
410
423
|
conflito: 'alterado localmente e no pacote, só com --forcar',
|
|
411
424
|
existente: 'já existe no projeto com outro conteúdo, será mantido',
|
|
425
|
+
mantido: 'rule antiga do harness alterada localmente, será mantida e retirada do lock',
|
|
412
426
|
'modificado-local': 'alterado localmente, será mantido',
|
|
413
427
|
};
|
|
414
428
|
export function describeUpdate(report) {
|
|
@@ -422,7 +436,7 @@ export function describeUpdate(report) {
|
|
|
422
436
|
const nucleo = report.registrarHooksNucleo ? [`Faltam hooks do harness em ${SETTINGS_PATH}; o --yes registra os que faltam.`] : [];
|
|
423
437
|
const permission = report.permissaoAusente && !report.adotada
|
|
424
438
|
? [
|
|
425
|
-
`Faltam permissões do harness em .claude/settings.json (${report.permissoesFaltando.join(', ')}); o --yes as
|
|
439
|
+
`Faltam permissões do harness em .claude/settings.json (${report.permissoesFaltando.join(', ')}); o --yes as aplica.`,
|
|
426
440
|
]
|
|
427
441
|
: [];
|
|
428
442
|
const comentarios = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fontdata/ai-harness",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "Harness de engenharia com IA da Fontdata para Claude Code: roda os slash commands direto na pasta do projeto via npx, sem instalar nada — ou instala-os em .claude/commands.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { homedir, tmpdir } from 'node:os';
|
|
4
|
+
import { basename, dirname, join, resolve, sep } from 'node:path';
|
|
5
|
+
import { runHook } from './lib/hook.mjs';
|
|
6
|
+
|
|
7
|
+
const SEM_CAIXA = process.platform === 'darwin' || process.platform === 'win32';
|
|
8
|
+
|
|
9
|
+
/** Resolve os links pelo maior ancestral que existe, porque o alvo pode não existir. @param {string} caminho */
|
|
10
|
+
function normalizar(caminho) {
|
|
11
|
+
let atual = resolve(caminho);
|
|
12
|
+
/** @type {string[]} */
|
|
13
|
+
const resto = [];
|
|
14
|
+
for (;;) {
|
|
15
|
+
try {
|
|
16
|
+
const real = realpathSync.native(atual);
|
|
17
|
+
return resto.length ? join(real, ...resto.reverse()) : real;
|
|
18
|
+
} catch {
|
|
19
|
+
const pai = dirname(atual);
|
|
20
|
+
if (pai === atual) return resolve(caminho);
|
|
21
|
+
resto.push(basename(atual));
|
|
22
|
+
atual = pai;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {string} caminho */
|
|
28
|
+
const chave = (caminho) => (SEM_CAIXA ? caminho.toLowerCase() : caminho);
|
|
29
|
+
|
|
30
|
+
/** @param {string} caminho @param {string} base ambos já normalizados */
|
|
31
|
+
function dentro(caminho, base) {
|
|
32
|
+
const c = chave(caminho);
|
|
33
|
+
const b = chave(base);
|
|
34
|
+
return c === b || c.startsWith(b.endsWith(sep) ? b : b + sep);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {string} raiz @param {string} alvo @returns {{ id: string, motivo: string, decisao: 'negar' | 'perguntar' } | null} */
|
|
38
|
+
function avaliar(raiz, alvo) {
|
|
39
|
+
const home = normalizar(homedir());
|
|
40
|
+
const emHome = (/** @type {string[]} */ ...partes) => normalizar(join(home, ...partes));
|
|
41
|
+
const emRaiz = (/** @type {string[]} */ ...partes) => normalizar(join(raiz, ...partes));
|
|
42
|
+
const igual = (/** @type {string} */ outro) => chave(alvo) === chave(outro);
|
|
43
|
+
|
|
44
|
+
if (alvo.split(sep).some((segmento) => chave(segmento) === '.git')) {
|
|
45
|
+
return { id: 'git-interno', motivo: `${alvo} fica dentro de .git/; gravar ali corrompe o repositório`, decisao: 'negar' };
|
|
46
|
+
}
|
|
47
|
+
const credenciais = [['.ssh'], ['.aws'], ['.config', 'gh'], ['.gnupg']].map((partes) => emHome(...partes));
|
|
48
|
+
if (credenciais.some((pasta) => dentro(alvo, pasta))) {
|
|
49
|
+
return { id: 'credenciais', motivo: `${alvo} fica numa pasta de credenciais do usuário`, decisao: 'negar' };
|
|
50
|
+
}
|
|
51
|
+
if (igual(emRaiz('.ai-harness', 'lock.json'))) {
|
|
52
|
+
return { id: 'lock-harness', motivo: 'o .ai-harness/lock.json só é gravado pelo init e pelo update do ai-harness', decisao: 'negar' };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const protecao = [
|
|
56
|
+
emRaiz('.ai-harness', 'config.json'),
|
|
57
|
+
emRaiz('.claude', 'settings.json'),
|
|
58
|
+
emRaiz('.claude', 'settings.local.json'),
|
|
59
|
+
emHome('.claude', 'settings.json'),
|
|
60
|
+
emHome('.claude', 'settings.local.json'),
|
|
61
|
+
];
|
|
62
|
+
if (protecao.some(igual)) {
|
|
63
|
+
return { id: 'protecao-propria', motivo: `${alvo} configura os hooks e permissões; alterá-lo pode desligar a proteção`, decisao: 'perguntar' };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const liberadas = [raiz, normalizar(tmpdir()), normalizar('/tmp'), normalizar('/private/tmp'), emHome('.claude')];
|
|
67
|
+
if (liberadas.some((pasta) => dentro(alvo, pasta))) return null;
|
|
68
|
+
return { id: 'fora-da-raiz', motivo: `${alvo} fica fora da raiz do projeto (${raiz})`, decisao: 'perguntar' };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await runHook('arquivo-sensivel', (input, { root }) => {
|
|
72
|
+
const caminho = input.tool_input?.file_path ?? input.tool_input?.notebook_path;
|
|
73
|
+
if (caminho === undefined || caminho === null || caminho === '') return null;
|
|
74
|
+
if (typeof caminho !== 'string') {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`o caminho do arquivo não é texto (${typeof caminho}); se o hook travar gravações válidas, ponha ` +
|
|
77
|
+
'hooks.arquivo-sensivel em "aviso" no .ai-harness/config.json até a correção'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const raiz = normalizar(root);
|
|
81
|
+
const regra = avaliar(raiz, normalizar(resolve(raiz, caminho)));
|
|
82
|
+
return regra && { motivo: `${regra.id}: ${regra.motivo}`, decisao: regra.decisao };
|
|
83
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { invocacao, palavras, segmentos, semTextoLivre } from './lib/comando-texto.mjs';
|
|
3
|
+
import { segurancaConfig } from './lib/config.mjs';
|
|
4
|
+
import { runHook } from './lib/hook.mjs';
|
|
5
|
+
import { findActiveWorks } from './lib/rastro.mjs';
|
|
6
|
+
import { REGRAS as APAGAR } from './lib/regras/apagar.mjs';
|
|
7
|
+
import { REGRAS as GIT } from './lib/regras/git.mjs';
|
|
8
|
+
import { REGRAS as REMOTO } from './lib/regras/remoto.mjs';
|
|
9
|
+
import { REGRAS as SQL } from './lib/regras/sql.mjs';
|
|
10
|
+
|
|
11
|
+
const TODAS = [...APAGAR, ...GIT, ...SQL, ...REMOTO];
|
|
12
|
+
const REGRAS = [...TODAS.filter((r) => r.decisao === 'negar'), ...TODAS.filter((r) => r.decisao === 'perguntar')];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Os segmentos e, depois de cada um, os do script passado a `sh -c`, `pwsh -Command` ou `cmd /c`.
|
|
16
|
+
* @param {string[]} lista @param {number} [profundidade] @returns {string[]} */
|
|
17
|
+
function comScriptsInternos(lista, profundidade = 0) {
|
|
18
|
+
return lista.flatMap((segmento) => {
|
|
19
|
+
const { nome, args } = invocacao(palavras(segmento));
|
|
20
|
+
let script = null;
|
|
21
|
+
if (['sh', 'bash', 'zsh', 'dash', 'ksh'].includes(nome)) {
|
|
22
|
+
const k = args.findIndex((a) => /^-[a-z]*c[a-z]*$/i.test(a));
|
|
23
|
+
if (k !== -1) script = args[k + 1] ?? null;
|
|
24
|
+
} else if (['pwsh', 'powershell'].includes(nome)) {
|
|
25
|
+
const k = args.findIndex((a) => /^-c(ommand)?$/i.test(a));
|
|
26
|
+
if (k !== -1) script = args.slice(k + 1).join(' ');
|
|
27
|
+
} else if (nome === 'cmd') {
|
|
28
|
+
const k = args.findIndex((a) => /^\/[ck]$/i.test(a));
|
|
29
|
+
if (k !== -1) script = args.slice(k + 1).join(' ');
|
|
30
|
+
}
|
|
31
|
+
if (!script || profundidade >= 3) return [segmento];
|
|
32
|
+
return [segmento, ...comScriptsInternos(segmentos(semTextoLivre(script)), profundidade + 1)];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @param {string} comando */
|
|
37
|
+
function rodarComExclamacao(comando) {
|
|
38
|
+
const linha = comando.trim();
|
|
39
|
+
return !linha.includes('\n') && linha.length <= 200 ? `! ${linha}` : '! <comando>';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await runHook('comando-destrutivo', (input, { root }) => {
|
|
43
|
+
const comando = input.tool_input?.command;
|
|
44
|
+
if (comando === undefined || comando === null) return null;
|
|
45
|
+
try {
|
|
46
|
+
if (typeof comando !== 'string') throw new Error(`tool_input.command não é texto (${typeof comando})`);
|
|
47
|
+
/** @type {string[] | undefined} */
|
|
48
|
+
let ativos;
|
|
49
|
+
/** @type {import('./lib/comando-texto.mjs').ContextoComando} */
|
|
50
|
+
const ctx = {
|
|
51
|
+
comando,
|
|
52
|
+
segmentos: comScriptsInternos(segmentos(semTextoLivre(comando))),
|
|
53
|
+
raiz: root,
|
|
54
|
+
seguranca: segurancaConfig(root),
|
|
55
|
+
get trabalhosAtivos() {
|
|
56
|
+
return (ativos ??= findActiveWorks(root));
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const regra = REGRAS.find((r) => r.testar(ctx));
|
|
60
|
+
if (!regra) return null;
|
|
61
|
+
if (regra.decisao === 'perguntar') return { motivo: `${regra.id}: ${regra.motivo}`, decisao: 'perguntar' };
|
|
62
|
+
return {
|
|
63
|
+
motivo:
|
|
64
|
+
`${regra.id}: ${regra.motivo}. O agente não roda este comando; se for isso mesmo, o dev pode rodá-lo ele ` +
|
|
65
|
+
`mesmo na sessão com ${rodarComExclamacao(comando)}`,
|
|
66
|
+
decisao: 'negar',
|
|
67
|
+
};
|
|
68
|
+
} catch (erro) {
|
|
69
|
+
const motivo = erro instanceof Error ? erro.message : String(erro);
|
|
70
|
+
throw new Error(
|
|
71
|
+
`${motivo}; se o hook travar comandos válidos, ponha hooks.comando-destrutivo em "aviso" no .ai-harness/config.json até a correção`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -9,9 +9,16 @@
|
|
|
9
9
|
],
|
|
10
10
|
"PreToolUse": [
|
|
11
11
|
{
|
|
12
|
-
"matcher": "Bash",
|
|
12
|
+
"matcher": "Bash|PowerShell",
|
|
13
13
|
"hooks": [
|
|
14
|
-
{ "type": "command", "
|
|
14
|
+
{ "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/templates/hooks/segredo-no-commit.mjs\"" },
|
|
15
|
+
{ "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/templates/hooks/comando-destrutivo.mjs\"" }
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"matcher": "Edit|Write|MultiEdit|NotebookEdit",
|
|
20
|
+
"hooks": [
|
|
21
|
+
{ "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/templates/hooks/arquivo-sensivel.mjs\"" }
|
|
15
22
|
]
|
|
16
23
|
},
|
|
17
24
|
{
|