Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ Der Bot akzeptiert derzeit:
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>Befehl zum Starten von Codex CLI. Standard: <code>codex</code>.</td>
<td>Befehl zum Starten von Codex CLI. Die Anwendung versucht beim Initialisieren der <code>.env_coding_agent_telegram</code>-Datei, den lokal installierten Codex-Pfad automatisch zu erkennen. Alternativ können Sie mit <code>which codex</code> den Pfad anzeigen.</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>Befehl zum Starten von Copilot CLI. Standard: <code>copilot</code>.</td>
<td>Befehl zum Starten von Copilot CLI. Die Anwendung versucht beim Initialisieren der <code>.env_coding_agent_telegram</code>-Datei, den lokal installierten Copilot-Pfad automatisch zu erkennen. Alternativ können Sie mit <code>which copilot</code> den Pfad anzeigen.</td>
</tr>
<tr>
<td><code>CLAUDE_BIN</code></td>
<td>Befehl zum Starten von Claude Code CLI. Standard: <code>~/.local/bin/claude</code>.</td>
<td>Befehl zum Starten von Claude Code CLI. Die Anwendung versucht beim Initialisieren der <code>.env_coding_agent_telegram</code>-Datei, den lokal installierten Claude-Pfad automatisch zu erkennen. Alternativ können Sie mit <code>which claude</code> den Pfad anzeigen.</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ Le bot accepte actuellement :
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>Commande utilisée pour lancer Codex CLI. Valeur par défaut : <code>codex</code>.</td>
<td>Commande utilisée pour lancer Codex CLI. L'application essaiera de détecter automatiquement le chemin d'installation local de Codex lors de l'initialisation de <code>.env_coding_agent_telegram</code>. Vous pouvez également utiliser <code>which codex</code> pour afficher ce chemin.</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>Commande utilisée pour lancer Copilot CLI. Valeur par défaut : <code>copilot</code>.</td>
<td>Commande utilisée pour lancer Copilot CLI. L'application essaiera de détecter automatiquement le chemin d'installation local de Copilot lors de l'initialisation de <code>.env_coding_agent_telegram</code>. Vous pouvez également utiliser <code>which copilot</code> pour afficher ce chemin.</td>
</tr>
<tr>
<td width="332"><code>CLAUDE_BIN</code></td>
<td>Commande utilisée pour lancer Claude Code CLI. Valeur par défaut : <code>~/.local/bin/claude</code>.</td>
<td>Commande utilisée pour lancer Claude Code CLI. L'application essaiera de détecter automatiquement le chemin d'installation local de Claude lors de l'initialisation de <code>.env_coding_agent_telegram</code>. Vous pouvez également utiliser <code>which claude</code> pour afficher ce chemin.</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>Codex CLI を起動するコマンドです。既定値: <code>codex</code>.</td>
<td>Codex CLI を起動するコマンドです。アプリは <code>.env_coding_agent_telegram</code> の初期化時に、ローカルにインストールされている Codex のパスを自動的に検出します。別の方法として、<code>which codex</code> を使用してパスを確認できます。</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>Copilot CLI を起動するコマンドです。既定値: <code>copilot</code>.</td>
<td>Copilot CLI を起動するコマンドです。アプリは <code>.env_coding_agent_telegram</code> の初期化時に、ローカルにインストールされている Copilot のパスを自動的に検出します。別の方法として、<code>which copilot</code> を使用してパスを確認できます。</td>
</tr>
<tr>
<td><code>CLAUDE_BIN</code></td>
<td>Claude Code CLI を起動するコマンドです。既定値: <code>~/.local/bin/claude</code>.</td>
<td>Claude Code CLI を起動するコマンドです。アプリは <code>.env_coding_agent_telegram</code> の初期化時に、ローカルにインストールされている Claude のパスを自動的に検出します。別の方法として、<code>which claude</code> を使用してパスを確認できます。</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>Codex CLI 를 실행할 명령입니다. 기본값: <code>codex</code>.</td>
<td>Codex CLI 를 실행할 명령입니다. 앱은 <code>.env_coding_agent_telegram</code>를 초기화할 때 로컬에 설치된 Codex 경로를 자동으로 감지합니다. 또는 <code>which codex</code>를 사용하여 경로를 확인할 수 있습니다.</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>Copilot CLI 를 실행할 명령입니다. 기본값: <code>copilot</code>.</td>
<td>Copilot CLI 를 실행할 명령입니다. 앱은 <code>.env_coding_agent_telegram</code>를 초기화할 때 로컬에 설치된 Copilot 경로를 자동으로 감지합니다. 또는 <code>which copilot</code>를 사용하여 경로를 확인할 수 있습니다.</td>
</tr>
<tr>
<td width="332"><code>CLAUDE_BIN</code></td>
<td>Claude Code CLI 를 실행할 명령입니다. 기본값: <code>~/.local/bin/claude</code>.</td>
<td>Claude Code CLI 를 실행할 명령입니다. 앱은 <code>.env_coding_agent_telegram</code>를 초기화할 때 로컬에 설치된 Claude 경로를 자동으로 감지합니다. 또는 <code>which claude</code>를 사용하여 경로를 확인할 수 있습니다.</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ The bot currently accepts:
</tr>
<tr>
<td><code>CODEX_BIN</code></td>
<td>Command used to launch Codex CLI. Default: <code>codex</code>.</td>
<td>Command used to launch Codex CLI. The app would try to detect the locally installed Codex path when initializing the <code>.env_coding_agent_telegram</code>. Alternatively use <code>which codex</code> to view the path. </td>
</tr>
<tr>
<td><code>COPILOT_BIN</code></td>
<td>Command used to launch Copilot CLI. Default: <code>copilot</code>.</td>
<td>Command used to launch Copilot CLI. The app would try to detect the locally installed Copilot path when initializing the <code>.env_coding_agent_telegram</code>. Alternatively use <code>which copilot</code> to view the path. </td>
</tr>
<tr>
<td><code>CLAUDE_BIN</code></td>
<td>Command used to launch Claude Code CLI. Default: <code>~/.local/bin/claude</code>.</td>
<td>Command used to launch Claude Code CLI. The app would try to detect the locally installed Claude path when initializing the <code>.env_coding_agent_telegram</code>. Alternatively use <code>which claude</code> to view the path. </td>
</tr>
<tr>
<td><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ De bot accepteert momenteel:
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>Commando om Codex CLI te starten. Standaard: <code>codex</code>.</td>
<td>Commando om Codex CLI te starten. De applicatie probeert tijdens het initialiseren van <code>.env_coding_agent_telegram</code> automatisch het lokaal geïnstalleerde Codex-pad te detecteren. U kunt ook <code>which codex</code> gebruiken om het pad weer te geven.</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>Commando om Copilot CLI te starten. Standaard: <code>copilot</code>.</td>
<td>Commando om Copilot CLI te starten. De applicatie probeert tijdens het initialiseren van <code>.env_coding_agent_telegram</code> automatisch het lokaal geïnstalleerde Copilot-pad te detecteren. U kunt ook <code>which copilot</code> gebruiken om het pad weer te geven.</td>
</tr>
<tr>
<td width="332"><code>CLAUDE_BIN</code></td>
<td>Commando om Claude Code CLI te starten. Standaard: <code>~/.local/bin/claude</code>.</td>
<td>Commando om Claude Code CLI te starten. De applicatie probeert tijdens het initialiseren van <code>.env_coding_agent_telegram</code> automatisch het lokaal geïnstalleerde Claude-pad te detecteren. U kunt ook <code>which claude</code> gebruiken om het pad weer te geven.</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.th.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>คำสั่งที่ใช้เรียก Codex CLI ค่าเริ่มต้น: <code>codex</code></td>
<td>คำสั่งที่ใช้เรียก Codex CLI. แอปจะพยายามตรวจหาเส้นทางของ Codex ที่ติดตั้งอยู่ในเครื่องโดยอัตโนมัติระหว่างการเริ่มต้น <code>.env_coding_agent_telegram</code> หรือสามารถใช้ <code>which codex</code> เพื่อดูเส้นทางได้</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>คำสั่งที่ใช้เรียก Copilot CLI ค่าเริ่มต้น: <code>copilot</code></td>
<td>คำสั่งที่ใช้เรียก Copilot CLI. แอปจะพยายามตรวจหาเส้นทางของ Copilot ที่ติดตั้งอยู่ในเครื่องโดยอัตโนมัติระหว่างการเริ่มต้น <code>.env_coding_agent_telegram</code> หรือสามารถใช้ <code>which copilot</code> เพื่อดูเส้นทางได้</td>
</tr>
<tr>
<td><code>CLAUDE_BIN</code></td>
<td>คำสั่งที่ใช้เรียก Claude Code CLI ค่าเริ่มต้น: <code>~/.local/bin/claude</code></td>
<td>คำสั่งที่ใช้เรียก Claude Code CLI. แอปจะพยายามตรวจหาเส้นทางของ Claude ที่ติดตั้งอยู่ในเครื่องโดยอัตโนมัติระหว่างการเริ่มต้น <code>.env_coding_agent_telegram</code> หรือสามารถใช้ <code>which claude</code> เพื่อดูเส้นทางได้</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ Hiện tại bot chấp nhận:
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>Lệnh dùng để chạy Codex CLI. Mặc định: <code>codex</code>.</td>
<td>Lệnh dùng để chạy Codex CLI. Ứng dụng sẽ cố gắng tự động phát hiện đường dẫn của Codex được cài đặt trên máy khi khởi tạo <code>.env_coding_agent_telegram</code>. Ngoài ra, bạn có thể sử dụng <code>which codex</code> để xem đường dẫn.</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>Lệnh dùng để chạy Copilot CLI. Mặc định: <code>copilot</code>.</td>
<td>Lệnh dùng để chạy Copilot CLI. Ứng dụng sẽ cố gắng tự động phát hiện đường dẫn của Copilot được cài đặt trên máy khi khởi tạo <code>.env_coding_agent_telegram</code>. Ngoài ra, bạn có thể sử dụng <code>which copilot</code> để xem đường dẫn.</td>
</tr>
<tr>
<td width="332"><code>CLAUDE_BIN</code></td>
<td>Lệnh dùng để chạy Claude Code CLI. Mặc định: <code>~/.local/bin/claude</code>.</td>
<td>Lệnh dùng để chạy Claude Code CLI. Ứng dụng sẽ cố gắng tự động phát hiện đường dẫn của Claude được cài đặt trên máy khi khởi tạo <code>.env_coding_agent_telegram</code>. Ngoài ra, bạn có thể sử dụng <code>which claude</code> để xem đường dẫn.</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ bot 当前接受:
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>用于启动 Codex CLI 的命令。默认:<code>codex</code>。</td>
<td>用于启动 Codex CLI 的命令。应用程序会在初始化 <code>.env_coding_agent_telegram</code> 时尝试自动检测本地安装的 Codex 路径。您也可以使用 <code>which codex</code> 查看该路径。</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>用于启动 Copilot CLI 的命令。默认:<code>copilot</code>。</td>
<td>用于启动 Copilot CLI 的命令。应用程序会在初始化 <code>.env_coding_agent_telegram</code> 时尝试自动检测本地安装的 Copilot 路径。您也可以使用 <code>which copilot</code> 查看该路径。</td>
</tr>
<tr>
<td><code>CLAUDE_BIN</code></td>
<td>用于启动 Claude Code CLI 的命令。默认:<code>~/.local/bin/claude</code>。</td>
<td>用于启动 Claude Code CLI 的命令。应用程序会在初始化 <code>.env_coding_agent_telegram</code> 时尝试自动检测本地安装的 Claude 路径。您也可以使用 <code>which claude</code> 查看该路径。</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.zh-HK.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ bot 目前接受:
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>用來啟動 Codex CLI 的指令。預設:<code>codex</code>。</td>
<td>用來啟動 Codex CLI 的指令。應用程式會在初始化 <code>.env_coding_agent_telegram</code> 時嘗試自動偵測本機已安裝的 Codex 路徑。您亦可使用 <code>which codex</code> 查看該路徑。</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>用來啟動 Copilot CLI 的指令。預設:<code>copilot</code>。</td>
<td>用來啟動 Copilot CLI 的指令。應用程式會在初始化 <code>.env_coding_agent_telegram</code> 時嘗試自動偵測本機已安裝的 Copilot 路徑。您亦可使用 <code>which copilot</code> 查看該路徑。</td>
</tr>
<tr>
<td><code>CLAUDE_BIN</code></td>
<td>用來啟動 Claude Code CLI 的指令。預設:<code>~/.local/bin/claude</code>。</td>
<td>用來啟動 Claude Code CLI 的指令。應用程式會在初始化 <code>.env_coding_agent_telegram</code> 時嘗試自動偵測本機已安裝的 Claude 路徑。您亦可使用 <code>which claude</code> 查看該路徑。</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
6 changes: 3 additions & 3 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ bot 目前接受:
</tr>
<tr>
<td width="332"><code>CODEX_BIN</code></td>
<td>用來啟動 Codex CLI 的指令。預設:<code>codex</code>。</td>
<td>用來啟動 Codex CLI 的指令。應用程式會在初始化 <code>.env_coding_agent_telegram</code> 時嘗試自動偵測本機安裝的 Codex 路徑。您也可以使用 <code>which codex</code> 查看該路徑。</td>
</tr>
<tr>
<td width="332"><code>COPILOT_BIN</code></td>
<td>用來啟動 Copilot CLI 的指令。預設:<code>copilot</code>。</td>
<td>用來啟動 Copilot CLI 的指令。應用程式會在初始化 <code>.env_coding_agent_telegram</code> 時嘗試自動偵測本機安裝的 Copilot 路徑。您也可以使用 <code>which copilot</code> 查看該路徑。</td>
</tr>
<tr>
<td width="332"><code>CLAUDE_BIN</code></td>
<td>用來啟動 Claude Code CLI 的指令。預設:<code>~/.local/bin/claude</code>。</td>
<td>用來啟動 Claude Code CLI 的指令。應用程式會在初始化 <code>.env_coding_agent_telegram</code> 時嘗試自動偵測本機安裝的 Claude 路徑。您也可以使用 <code>which claude</code> 查看該路徑。</td>
</tr>
<tr>
<td width="332"><code>CODEX_MODEL</code></td>
Expand Down
8 changes: 8 additions & 0 deletions src/coding_agent_telegram/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def main() -> None:
raise

store = SessionStore(cfg.state_file, cfg.state_backup_file)
cleared_pending_actions = store.clear_all_pending_actions()
if cleared_pending_actions:
logger.warning(
"Cleared %d stale pending_action entr%s left over from a previous run "
"(likely an unclean shutdown mid-message); affected chats can send messages again.",
cleared_pending_actions,
"y" if cleared_pending_actions == 1 else "ies",
)
runner = MultiAgentRunner(
codex_bin=cfg.codex_bin,
copilot_bin=cfg.copilot_bin,
Expand Down
58 changes: 57 additions & 1 deletion src/coding_agent_telegram/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import pwd
import re
import shutil
import locale as system_locale
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -134,6 +135,59 @@ def _apply_initial_app_locale(template_text: str, app_locale: str) -> str:
return f"{replacement}\n{template_text}"


# Fallback install locations checked when a CLI isn't on PATH, e.g. because the
# process runs under a service manager or a shell profile that startup.sh
# doesn't source. Order matters: earlier entries win when a bin exists in
# more than one of them.
_BIN_CANDIDATE_DIRS = (
"~/.local/bin",
"~/bin",
"/opt/homebrew/bin",
"/usr/local/bin",
"/usr/bin",
"~/.npm-global/bin",
"~/.volta/bin",
)


def detect_installed_bin(bin_name: str) -> Optional[str]:
"""Return the absolute path of a locally installed CLI, or None if not found.

Deliberately does not resolve symlinks to their final target (e.g. a
version manager's ``.local/bin/claude`` -> ``.local/share/claude/versions/x.y.z``):
keeping the symlink path lets in-place CLI upgrades keep working without
editing the env file again.
"""
found = shutil.which(bin_name)
if found:
return str(Path(found).absolute())
for candidate_dir in _BIN_CANDIDATE_DIRS:
candidate = Path(candidate_dir).expanduser() / bin_name
if candidate.is_file() and os.access(candidate, os.X_OK):
return str(candidate.absolute())
return None


# Maps each provider's env var name to the CLI executable it looks for.
_PROVIDER_BIN_ENV_VARS = (
("CODEX_BIN", "codex"),
("COPILOT_BIN", "copilot"),
("CLAUDE_BIN", "claude"),
)


def _apply_detected_provider_bins(template_text: str) -> str:
text = template_text
for env_var, bin_name in _PROVIDER_BIN_ENV_VARS:
detected_path = detect_installed_bin(bin_name)
if not detected_path:
continue
pattern = rf"(?m)^{env_var}=.*$"
if re.search(pattern, text):
text = re.sub(pattern, f"{env_var}={detected_path}", text, count=1)
return text


def create_initial_env_file(env_path: Path, template_path: Optional[Path] = None) -> str:
if template_path is None:
template_text = importlib.resources.files("coding_agent_telegram").joinpath("resources/.env.example").read_text(
Expand All @@ -143,7 +197,9 @@ def create_initial_env_file(env_path: Path, template_path: Optional[Path] = None
template_text = template_path.read_text(encoding="utf-8")
app_locale = detect_system_locale()
env_path.parent.mkdir(parents=True, exist_ok=True)
env_path.write_text(_apply_initial_app_locale(template_text, app_locale), encoding="utf-8")
template_text = _apply_initial_app_locale(template_text, app_locale)
template_text = _apply_detected_provider_bins(template_text)
env_path.write_text(template_text, encoding="utf-8")
return app_locale


Expand Down
Loading
Loading