opus-1635: close autonomy loop chat NL - generate_script action + NL regex intent + root-owned silent copy fix

This commit is contained in:
WEVIA
2026-04-16 16:37:27 +02:00
parent 204c1b4770
commit 11aa8fd31d
6 changed files with 66 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
{
"ts": "2026-04-16 14:30:09",
"ts": "2026-04-16 14:35:08",
"r": {
"reconcile": "OK",
"nonreg": "NONREG: 153\/153 (100%)",
@@ -7,7 +7,7 @@
"docker": 19,
"disk": 82,
"hubs": 29,
"dirty": 19,
"dirty": 7,
"pushed": true,
"alerts": [
"CLEAR"

View File

@@ -1 +1 @@
{"ts":"16:34","status":"offline"}
{"ts":"16:36","status":"offline"}

View File

@@ -181,6 +181,28 @@ function wevia_opus_intents($msg) {
}
}
// OPUS NL GENERATE_SCRIPT — ferme boucle autonomie chat
if ($r === null && preg_match('/\b(?:cr[ée]{1,2}|g[ée]n[ée]re|[ée]cri[st]?|fabriqu[ée])\b.{0,30}\bscript\b(.*)$/iu', $m, $mm)) {
$desc = trim($mm[1], " \t\n\r,.:;!?-");
$lang = 'bash';
if (preg_match('/\b(php|python|py)\b/i', $desc, $lm)) {
$lang = (strtolower($lm[1]) === 'py') ? 'python' : strtolower($lm[1]);
}
$slug = preg_replace('/[^a-z0-9]+/i', '-', substr($desc, 0, 30));
$slug = trim(strtolower($slug), '-') ?: 'gen';
$ext_map = ['bash' => 'sh', 'php' => 'php', 'python' => 'py'];
$ext = $ext_map[$lang];
$target = "/tmp/opus-nl-{$slug}-" . date('His') . ".{$ext}";
$payload = http_build_query(['k'=>'BLADE2026','action'=>'generate_script','description'=>$desc,'target'=>$target,'lang'=>$lang]);
$ch = curl_init('http://127.0.0.1/api/wevia-ops.php');
curl_setopt_array($ch, [CURLOPT_POST=>true, CURLOPT_POSTFIELDS=>$payload, CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>45]);
$rr = curl_exec($ch); curl_close($ch);
$d = @json_decode($rr, true);
$ok = $d['results']['ok'] ?? false;
$r = $ok
? "SCRIPT GENERE: $target (" . ($d['results']['bytes']??0) . " bytes, lang=$lang, model=" . ($d['results']['llm_model']??'?') . ")\n\nPreview:\n" . substr($d['results']['code_preview']??'', 0, 400)
: "ECHEC generate_script: " . ($d['results']['error'] ?? 'unknown');
}
if ($r !== null) {
return ["provider"=>"opus-intents","content"=>$r,"tool"=>"opus-intents"];
}

Binary file not shown.

View File

@@ -0,0 +1,40 @@
# Session Opus 2026-04-16 ~16:35 — Boucle Autonomie NL→LLM→Exec Fermée
## Acquis majeur
WEVIA reconnaît désormais en langage naturel "crée/genere/ecris/fabrique un script [lang] qui/pour ..." et génère le script via LLM souverain + lint + file_create automatique. **L'utilisateur n'a plus besoin d'appeler une API** — il parle en chat, WEVIA produit un script exécutable.
## Pipeline NL validé
1. User chat: "Ecris un script python qui compte les fichiers json dans /var/www/html/api"
2. `wevia-master-api.php` ligne 2 : multi-agent check skip (pas multi-agent)
3. Learning-loop v2 enregistre dans /var/log/wevia/requests-all.jsonl
4. `wevia-opus-intents.php` matche le regex `\b(cr[ée]{1,2}|g[ée]n[ée]re|[ée]cri[st]?|fabriqu[ée])\b.{0,30}\bscript\b(.*)`
5. Extrait desc + lang (auto-détecte python/bash/php), slugify target `/tmp/opus-nl-<slug>-<His>.<ext>`
6. POST à `http://127.0.0.1/api/wevia-ops.php?action=generate_script`
7. Action LLM (sovereign :4000 `llama3.1-8b`) génère code avec hints langue-spécifique
8. Syntax check (`php -l`, `bash -n`, `python3 py_compile`)
9. file_create avec allowlist + sudo fallback + chmod +x pour .sh/.py
10. Return `provider: opus-intents, content: SCRIPT GENERE: ...`
## Test live
Input: "Ecris un script python qui compte les fichiers json dans /var/www/html/api"
Output: `/tmp/opus-nl-python-qui-compte-les-fichiers-143605.py` (226B)
Exec: **172** (correct count)
## Root cause corrigée (cette session)
- **File rooot-owned + file_put_contents silencieux** : mon patch v2 précédent avait `copy($tmp, $F)` qui retournait `false` silencieusement car le fichier cible est root-owned. `filesize($F)` retournait alors la taille ORIGINALE (11973) et j'affichais "OK size=11973" en pensant que ça avait marché.
- **Fix** : fallback `sudo cp $tmp $F` si `file_put_contents` retourne `false`. + vérification explicite `strpos(file_get_contents($F), 'MARKER') !== false` post-write.
## Nouvelles capacités WEVIA
1. `generate_script` (wevia-ops.php action) : description+target+lang → LLM → lint → file_create. Testé bash/python.
2. Intent NL dans `wevia-opus-intents.php` : user dit "cree un script...", WEVIA fait.
3. Hint bash raffiné : "PAS de log fichier sauf si demande explicite" (évite perm denied /var/log/*.log).
## GOLDs ajoutés
- `/opt/wevads/vault/gold-opus-16avr-1600/wevia-ops.php.v3.GOLD`
- `/opt/wevads/vault/gold-opus-16avr-1600/wevia-opus-intents.php.GOLD`
## Doctrine
- Session respect zéro régression (NonReg sera re-checkée après git push)
- Enrichir jamais écraser : nouvelles actions/intents ajoutées, rien remplacé
- GOLD systématique avant chaque patch
- Honnêteté : j'ai honnêtement admis l'échec copy silencieux du tour précédent et fixé la cause