refactor(brain): Auto-Magie raus — ARIA entscheidet selbst, Stefan fragt im Zweifel

Mut zur Luecke: -595 Zeilen Auto-Magie-Code raus, weil sie heute Abend
4 Bugs verursacht und 0 echten Mehrwert geliefert hat. Plus Stefan
hat zu Recht erkannt dass das System mit Pentest/Audit-Workflows
kollidieren wuerde (Whitelist-Pflege noetig).

Weg:
- aria-brain/api_heuristic.py geloescht (282 Zeilen Cross-Session-
  Tracking, Hint-Generation, Bypass-Detection)
- aria-brain/agent.py: Auto-Scaffold-Block, Bypass-Detection-Block,
  _upsert_bypass_lesson-Methode (-146 Zeilen)
- aria-brain/main.py: /skills/can-bash-host Endpoint
- aria-brain/prompts.py: api_heuristic_section-Parameter
- docker-compose.yml: managed-settings-Copy aus proxy-Command
- proxy-patches/pre-tool-bash-block.js (PreToolUse-Hook)
- proxy-patches/managed-settings.json (claude-CLI Hook-Config)

Bleibt (kostet nichts, hilft):
- Alle 18 seed_rules (sind in DB, machen keine Last)
- skill_scaffold Tool (ARIA kann es manuell nutzen)
- Anti-Friedhof + snake_case + Safe-Name-Mapping (passive Validierung)
- Versionierung + Rollback (P4, hat sich bei PATH-Bug bewaehrt)
- 50k stdout Truncate-Fix

scaffold-reflex seed_rule umgeschrieben: kein 'SOFORT scaffold'-
Reflex mehr, stattdessen 4-Punkte-Heuristik (parametrisierbar?
wiederkehrend? exploratory? im Zweifel: Stefan fragen). Pentest-
Workflows bleiben damit ad-hoc Bash ohne false-positive
Skill-Vorschlaege.

Existierende auto-feedback-Memories in der DB bleiben — sind nuetzliche
Lehren, werden nicht mehr automatisch erweitert. Stefan kann sie via
Diagnostic-Gehirn-Tab loeschen wenn sie nerven.

Dank git ist alles rueckholbar. Wenn doch wieder Auto-Magie gewuenscht:
git revert auf 8d5991f.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-30 02:47:32 +02:00
parent 8d5991f364
commit d12bfd0302
9 changed files with 30 additions and 625 deletions
-15
View File
@@ -1,15 +0,0 @@
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "node /proxy-patches/pre-tool-bash-block.js"
}
]
}
]
}
}
-95
View File
@@ -1,95 +0,0 @@
#!/usr/bin/env node
/**
* ARIA claude-CLI PreToolUse-Hook: blockiert Bash-Calls gegen externe APIs
* fuer die bereits ein matching Skill im Brain existiert.
*
* Wird von claude-CLI PRO Tool-Use vor der Ausfuehrung mit dem Tool-Use-
* JSON via stdin aufgerufen. Wenn wir exit 2 mit Stderr returnen, lehnt
* claude-CLI den Tool-Call ab und gibt die Stderr als tool_use_error
* an das LLM zurueck — ARIA bekommt also eine echte Fehlermeldung und
* MUSS umdenken (nicht nur Prompt-Anweisung die sie ignorieren kann).
*
* Fail-open: bei jeder Art von Fehler (Brain nicht erreichbar, kaputtes
* JSON etc.) exit 0 — wir blockieren Stefan's eigentliche Arbeit nicht
* nur weil der Block-Mechanismus selber haengt.
*/
const http = require("http");
const BRAIN_URL = process.env.BRAIN_INTERNAL_URL || "http://aria-brain:8080";
const BRAIN_TIMEOUT_MS = 3000;
function fail_open(reason) {
if (process.env.HOOK_DEBUG) console.error(`hook-skip: ${reason}`);
process.exit(0);
}
function block(message) {
// exit 2 = block in claude-CLI PreToolUse hook contract
process.stderr.write(message);
process.exit(2);
}
let stdinBuf = "";
process.stdin.on("data", chunk => stdinBuf += chunk);
process.stdin.on("end", () => {
let payload;
try {
payload = JSON.parse(stdinBuf || "{}");
} catch (_) {
return fail_open("stdin not json");
}
// claude-CLI Hook-Format kann je nach Version variieren —
// wir akzeptieren tool_name oder hook_event_name in Kombination
const toolName = payload.tool_name || payload.tool || "";
if (toolName !== "Bash") return fail_open("tool != Bash");
const command = (payload.tool_input && payload.tool_input.command) ||
payload.command || "";
if (!command) return fail_open("no command");
// Schnellfilter: nur wenn ueberhaupt eine URL drin ist
if (!/https?:\/\//i.test(command)) return fail_open("no url");
// Brain fragen ob ein matching Skill existiert
const body = JSON.stringify({ command });
const req = http.request(
BRAIN_URL + "/skills/can-bash-host",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(body),
},
timeout: BRAIN_TIMEOUT_MS,
},
(res) => {
let chunks = "";
res.on("data", d => chunks += d);
res.on("end", () => {
let r;
try { r = JSON.parse(chunks); } catch (_) { return fail_open("brain bad json"); }
if (!r || !r.block) return fail_open("brain says ok");
const skill = r.skill || "?";
const host = r.host || "?";
const safeTool = r.safe_tool || `run_${skill}`;
const msg =
`🚨 BASH GEGEN ${host} BLOCKIERT.\n\n` +
`Es existiert bereits ein Skill '${skill}' fuer diesen Host. ` +
`Stefan hat das System so eingerichtet dass Skills via ` +
`\`${safeTool}\` direkt aufgerufen werden — das ist 5-10x ` +
`schneller als der Bash-Curl-Wrapper.\n\n` +
`Konkret: nutze JETZT \`${safeTool}\` mit den passenden ` +
`Parametern (method/path/body) statt curl. Wenn der Skill ` +
`nicht das liefert was Du brauchst: skill_update mit Fix, ` +
`nicht zurueck zu Bash.`;
block(msg);
});
}
);
req.on("error", () => fail_open("brain network error"));
req.on("timeout", () => { req.destroy(); fail_open("brain timeout"); });
req.write(body);
req.end();
});
// Falls stdin nie ein 'end' triggert — Timeout damit wir nicht haengen
setTimeout(() => fail_open("stdin timeout"), 4000);