From ddbe9de4bc8fde7156b62ce38ee0e552febc75e2 Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Sun, 30 Aug 2026 11:30:31 +0000 Subject: [PATCH] fix(discord-bridge): director de lucru dedicat + log nedublat - DEFAULT_CWD trece de la /workspace la /workspace/claude-agent, un spatiu cu git propriu, ca fisierele facute din Discord sa aiba istoric separat de proiectele reale. `!cd ` ramane disponibil oriunde in /workspace, deci decizia din plan (fara allowlist de proiecte) nu se schimba. - setup_logging: sub systemd unitul redirecteaza deja stdout in bot.log (StandardOutput=append:), iar FileHandler-ul scria fiecare linie a doua oara in acelasi fisier. FileHandler ramane doar la rulare manuala. Verificat in productie: bot conectat, un tur real incheiat curat (inflight null, cost $0.0742 contabilizat), restart fara orfani. Suita: 275 passed. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01B29CApsP1JkSdjYaGaHpE7 --- proxmox/lxc171-claude-agent/discord-bridge/bot.py | 13 +++++++++---- .../lxc171-claude-agent/discord-bridge/config.py | 2 +- .../discord-bridge/ops/env.example | 5 ++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/proxmox/lxc171-claude-agent/discord-bridge/bot.py b/proxmox/lxc171-claude-agent/discord-bridge/bot.py index 56157f0..baf8f00 100644 --- a/proxmox/lxc171-claude-agent/discord-bridge/bot.py +++ b/proxmox/lxc171-claude-agent/discord-bridge/bot.py @@ -480,7 +480,7 @@ class Bridge: "```", f"fir : {thread_id}", f"sesiune : {(proc.sid if proc is not None else None) or rec.get('sid') or '(noua)'}", - f"director : {rec.get('cwd') or config.get('DEFAULT_CWD', '/workspace')}", + f"director : {rec.get('cwd') or config.get('DEFAULT_CWD', '/workspace/claude-agent')}", f"model : {model}", f"proces : {'viu' if alive else 'oprit'}" + (f" pid={pid} rss={rss_mb(pid)} MB" if alive and pid else ""), @@ -528,7 +528,7 @@ class Bridge: channel = message.channel rec = self.store.thread(tid) model = rec.get("model") or default_model() - cwd = rec.get("cwd") or config.get("DEFAULT_CWD", "/workspace") + cwd = rec.get("cwd") or config.get("DEFAULT_CWD", "/workspace/claude-agent") turn_id = runner_mod.new_turn_id() try: @@ -676,8 +676,13 @@ def make_client(bridge: Bridge | None = None): # pragma: no cover - are nevoie def setup_logging() -> None: # pragma: no cover config.ensure_dirs() handlers: list[logging.Handler] = [logging.StreamHandler()] - with contextlib.suppress(OSError): - handlers.append(logging.FileHandler(pathlib.Path(config.LOG_DIR) / "bot.log")) + # Sub systemd, unitul redirecteaza deja stdout/stderr in bot.log + # (`StandardOutput=append:`). Un FileHandler peste asta ar scrie fiecare + # linie de doua ori in acelasi fisier. La rulare manuala nu exista + # redirectare, deci acolo tinem FileHandler-ul. + if not os.environ.get("INVOCATION_ID"): + with contextlib.suppress(OSError): + handlers.append(logging.FileHandler(pathlib.Path(config.LOG_DIR) / "bot.log")) logging.basicConfig( level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s", diff --git a/proxmox/lxc171-claude-agent/discord-bridge/config.py b/proxmox/lxc171-claude-agent/discord-bridge/config.py index f3d9c6a..9df8d2a 100644 --- a/proxmox/lxc171-claude-agent/discord-bridge/config.py +++ b/proxmox/lxc171-claude-agent/discord-bridge/config.py @@ -30,7 +30,7 @@ DEFAULTS: dict[str, str] = { "IDLE_REAP_S": "1200", "RATE_PER_USER_PER_MIN": "10", "CLAUDE_BIN": "claude", - "DEFAULT_CWD": "/workspace", + "DEFAULT_CWD": "/workspace/claude-agent", } diff --git a/proxmox/lxc171-claude-agent/discord-bridge/ops/env.example b/proxmox/lxc171-claude-agent/discord-bridge/ops/env.example index fdece9c..5a6d40b 100644 --- a/proxmox/lxc171-claude-agent/discord-bridge/ops/env.example +++ b/proxmox/lxc171-claude-agent/discord-bridge/ops/env.example @@ -48,4 +48,7 @@ CLAUDE_DISCORD_APPROVAL_TIMEOUT=300 ALERT_RECIPIENT=root # --- Directorul de lucru implicit ----------------------------------------- -DEFAULT_CWD=/workspace +# Directorul in care porneste un fir nou. Spatiu dedicat, cu git propriu, ca ce se +# face din Discord sa aiba istoric separat de proiectele reale. `!cd ` il +# schimba per fir, oriunde in /workspace. +DEFAULT_CWD=/workspace/claude-agent