Agents lancés isolés des réglages du poste (--setting-sources project,local, --strict-mcp-config) ; refus clair sans agents/ ou sans les liens d'Optimizer ; testé
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1d0a08b982
commit
1d80a77cb1
2 files changed
+19
-2
No files matched your search
@@ -41,6 +41,9 @@ optimisations = {}
|
|||||||
OCCUPE = "une optimisation des détecteurs est en cours"
|
OCCUPE = "une optimisation des détecteurs est en cours"
|
||||||
|
|
||||||
|
|
||||||
|
ISOLE = ["--setting-sources", "project,local", "--strict-mcp-config"] # ni plugins, ni hooks, ni serveurs MCP du poste
|
||||||
|
|
||||||
|
|
||||||
def _env():
|
def _env():
|
||||||
"""L'environnement de claude -p, sans clé d'API : les agents tournent sur l'abonnement Claude, jamais sur une clé."""
|
"""L'environnement de claude -p, sans clé d'API : les agents tournent sur l'abonnement Claude, jamais sur une clé."""
|
||||||
return {k: v for k, v in os.environ.items() if k not in ("ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN")}
|
return {k: v for k, v in os.environ.items() if k not in ("ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN")}
|
||||||
@@ -54,6 +57,8 @@ def lancer(corps):
|
|||||||
st, debut, fin = corps.get("station"), corps.get("debut"), corps.get("fin")
|
st, debut, fin = corps.get("station"), corps.get("debut"), corps.get("fin")
|
||||||
station._valide({"description": "-"}, debut, fin)
|
station._valide({"description": "-"}, debut, fin)
|
||||||
station.dossier(st)
|
station.dossier(st)
|
||||||
|
if not (AGENTS / ".claude-plugin" / "plugin.json").exists():
|
||||||
|
raise station.Refus("pas d'agents en agents/ (le lien : README.md)")
|
||||||
nom = f"{st}_{debut[:16].replace(':', '')}_{fin[:16].replace(':', '')}"
|
nom = f"{st}_{debut[:16].replace(':', '')}_{fin[:16].replace(':', '')}"
|
||||||
with verrou:
|
with verrou:
|
||||||
if _optimise():
|
if _optimise():
|
||||||
@@ -79,7 +84,7 @@ def travailler(nom, sortie, prompt, reprise=None):
|
|||||||
"""Un tour de l'analyste : la demande, ou un message de l'utilisateur dans la même session (reprise : son id)."""
|
"""Un tour de l'analyste : la demande, ou un message de l'utilisateur dans la même session (reprise : son id)."""
|
||||||
a = analyses[nom]
|
a = analyses[nom]
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen(["claude", "-p", prompt, "--plugin-dir", str(AGENTS), "--agent", "agents:analyste",
|
p = subprocess.Popen(["claude", "-p", prompt, "--plugin-dir", str(AGENTS), "--agent", "agents:analyste", *ISOLE,
|
||||||
"--output-format", "stream-json", "--verbose",
|
"--output-format", "stream-json", "--verbose",
|
||||||
"--allowedTools", "Read,Write,Bash", "--permission-mode", "acceptEdits", *station.liens()]
|
"--allowedTools", "Read,Write,Bash", "--permission-mode", "acceptEdits", *station.liens()]
|
||||||
+ (["--resume", reprise] if reprise else []),
|
+ (["--resume", reprise] if reprise else []),
|
||||||
@@ -255,6 +260,7 @@ def optimiser(nom):
|
|||||||
if etat(nom)["etat"] != "fini":
|
if etat(nom)["etat"] != "fini":
|
||||||
raise station.Refus("seule une analyse finie s'optimise")
|
raise station.Refus("seule une analyse finie s'optimise")
|
||||||
if not ((OPTIMIZER / ".claude" / "skills" / "improve" / "SKILL.md").exists()
|
if not ((OPTIMIZER / ".claude" / "skills" / "improve" / "SKILL.md").exists()
|
||||||
|
and all((OPTIMIZER / lien).exists() for lien in ("data", "labeling", "detectors"))
|
||||||
and (AGENTS / ".claude-plugin" / "plugin.json").exists()):
|
and (AGENTS / ".claude-plugin" / "plugin.json").exists()):
|
||||||
raise station.Refus("pas d'Optimizer en optimizer/ ou pas d'agents en agents/ (les liens : README.md)")
|
raise station.Refus("pas d'Optimizer en optimizer/ ou pas d'agents en agents/ (les liens : README.md)")
|
||||||
with verrou:
|
with verrou:
|
||||||
@@ -286,7 +292,7 @@ def optimiser_fil(nom):
|
|||||||
(station.RACINE, [f"Analyse : {rel}/. Outils : tools/. Écris {rel}/outils.md.", "--plugin-dir", str(AGENTS),
|
(station.RACINE, [f"Analyse : {rel}/. Outils : tools/. Écris {rel}/outils.md.", "--plugin-dir", str(AGENTS),
|
||||||
"--agent", "agents:tool-builder", "--allowedTools", "Read,Write,Edit,Bash"])]
|
"--agent", "agents:tool-builder", "--allowedTools", "Read,Write,Edit,Bash"])]
|
||||||
for dossier, (prompt, *options) in tours:
|
for dossier, (prompt, *options) in tours:
|
||||||
p = subprocess.Popen(["claude", "-p", prompt, "--output-format", "stream-json", "--verbose",
|
p = subprocess.Popen(["claude", "-p", prompt, *ISOLE, "--output-format", "stream-json", "--verbose",
|
||||||
"--permission-mode", "acceptEdits", *station.liens(), *options],
|
"--permission-mode", "acceptEdits", *station.liens(), *options],
|
||||||
cwd=dossier, env=_env(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
cwd=dossier, env=_env(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||||
for ligne in p.stdout:
|
for ligne in p.stdout:
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ def check_optimisation():
|
|||||||
assert "agents/" in leve(analyse.optimiser, "NORDEND_a")
|
assert "agents/" in leve(analyse.optimiser, "NORDEND_a")
|
||||||
(analyse.AGENTS / ".claude-plugin").mkdir(parents=True)
|
(analyse.AGENTS / ".claude-plugin").mkdir(parents=True)
|
||||||
(analyse.AGENTS / ".claude-plugin" / "plugin.json").write_text("{}")
|
(analyse.AGENTS / ".claude-plugin" / "plugin.json").write_text("{}")
|
||||||
|
assert "optimizer/" in leve(analyse.optimiser, "NORDEND_a") # sans les liens data, labeling, detectors d'Optimizer
|
||||||
|
for lien in ("data", "labeling", "detectors"):
|
||||||
|
(analyse.OPTIMIZER / lien).mkdir()
|
||||||
assert analyse.optimiser("NORDEND_a") == {}
|
assert analyse.optimiser("NORDEND_a") == {}
|
||||||
assert analyse.etat("NORDEND_a")["optimisation"]["etat"] == "en cours"
|
assert analyse.etat("NORDEND_a")["optimisation"]["etat"] == "en cours"
|
||||||
leve(analyse.optimiser, "NORDEND_a")
|
leve(analyse.optimiser, "NORDEND_a")
|
||||||
@@ -155,6 +158,8 @@ def check_optimisation():
|
|||||||
and "OUT: seances/NORDEND_a_" in requete, requete
|
and "OUT: seances/NORDEND_a_" in requete, requete
|
||||||
assert k["cwd"] == analyse.OPTIMIZER.resolve() and "--plugin-dir" in args, (args, k)
|
assert k["cwd"] == analyse.OPTIMIZER.resolve() and "--plugin-dir" in args, (args, k)
|
||||||
assert all("ANTHROPIC_API_KEY" not in kw["env"] for _, kw in lances), "une clé d'API passe à claude"
|
assert all("ANTHROPIC_API_KEY" not in kw["env"] for _, kw in lances), "une clé d'API passe à claude"
|
||||||
|
# isolés des réglages du poste (plugins, hooks, serveurs MCP de l'utilisateur)
|
||||||
|
assert all(a[a.index("--setting-sources") + 1] == "project,local" and "--strict-mcp-config" in a for a, _ in lances)
|
||||||
args, k = lances[1] # puis le tool-builder du dépôt agents, sur le dépôt tools
|
args, k = lances[1] # puis le tool-builder du dépôt agents, sur le dépôt tools
|
||||||
assert args[args.index("--agent") + 1] == "agents:tool-builder" and "Outils : tools/" in args[2], args
|
assert args[args.index("--agent") + 1] == "agents:tool-builder" and "Outils : tools/" in args[2], args
|
||||||
analyse.analyses["NORDEND_b"]["etat"] = "en cours" # une analyse qui tourne bloque l'optimisation
|
analyse.analyses["NORDEND_b"]["etat"] = "en cours" # une analyse qui tourne bloque l'optimisation
|
||||||
@@ -223,6 +228,7 @@ def check_analyse():
|
|||||||
assert args[args.index("--agent") + 1] == "agents:analyste" and "--plugin-dir" in args, args
|
assert args[args.index("--agent") + 1] == "agents:analyste" and "--plugin-dir" in args, args
|
||||||
assert "ANTHROPIC_API_KEY" not in k["env"] and "PATH" in k["env"], sorted(k.get("env") or {})
|
assert "ANTHROPIC_API_KEY" not in k["env"] and "PATH" in k["env"], sorted(k.get("env") or {})
|
||||||
assert "DETECTEURS : non" in args[2] and "CONSIGNES : consignes/analyste.md" in args[2], args[2]
|
assert "DETECTEURS : non" in args[2] and "CONSIGNES : consignes/analyste.md" in args[2], args[2]
|
||||||
|
assert args[args.index("--setting-sources") + 1] == "project,local" and "--strict-mcp-config" in args, args
|
||||||
(analyse.DOSSIER / nom / "travail" / "session").write_text("s-1")
|
(analyse.DOSSIER / nom / "travail" / "session").write_text("s-1")
|
||||||
analyse.message(nom, {"texte": "continue"})
|
analyse.message(nom, {"texte": "continue"})
|
||||||
while analyse.analyses[nom]["etat"] == "en cours":
|
while analyse.analyses[nom]["etat"] == "en cours":
|
||||||
@@ -231,6 +237,11 @@ def check_analyse():
|
|||||||
assert "ANTHROPIC_API_KEY" not in k["env"], sorted(k.get("env") or {})
|
assert "ANTHROPIC_API_KEY" not in k["env"], sorted(k.get("env") or {})
|
||||||
assert args[args.index("--resume") + 1] == "s-1" and args[args.index("--agent") + 1] == "agents:analyste" \
|
assert args[args.index("--resume") + 1] == "s-1" and args[args.index("--agent") + 1] == "agents:analyste" \
|
||||||
and "--plugin-dir" in args, args
|
and "--plugin-dir" in args, args
|
||||||
|
agents, analyse.AGENTS = analyse.AGENTS, analyse.DOSSIER / "sans-agents" # le lien agents/ manque : refus clair
|
||||||
|
try:
|
||||||
|
assert "agents/" in leve(analyse.lancer, {"station": "NORDEND", "debut": "2026-11-06T06:00Z", "fin": "2026-11-06T12:00Z"})
|
||||||
|
finally:
|
||||||
|
analyse.AGENTS = agents
|
||||||
finally:
|
finally:
|
||||||
os.environ.pop("ANTHROPIC_API_KEY")
|
os.environ.pop("ANTHROPIC_API_KEY")
|
||||||
if cle is not None:
|
if cle is not None:
|
||||||
|
|||||||
Reference in new issue
Block a user