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
12 changes: 10 additions & 2 deletions README.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ Der Bot akzeptiert derzeit:
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>Nach Bestätigung <code>origin</code> in den Branch der aktiven Session pullen. Wenn zutreffend, aktualisiert der Bot zusätzlich den Standard-Branch.</td>
<td>Nach Bestätigung per Git von <code>origin</code> in den Branch der aktiven Session pullen. Wenn zutreffend, aktualisiert der Bot zusätzlich den Standard-Branch.</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td><code>origin &lt;branch&gt;</code> für die aktuelle aktive Session pushen. Der Bot fragt vor dem Push nach einer Bestätigung.</td>
<td>Per Git <code>origin &lt;branch&gt;</code> für die aktuelle aktive Session pushen. Der Bot fragt vor dem Push nach einer Bestätigung.</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>Die letzten fünf Git-Commits für das Projekt der aktiven Session anzeigen.</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>Einen lokalen oder <code>origin</code>-Standard-/aktuellen Branch auswählen und anschließend <code>git reset --hard</code> bestätigen. Remote-Ziele werden zuerst gepullt.</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ Le bot accepte actuellement :
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>Après confirmation, exécuter un <code>pull</code> depuis <code>origin</code> pour la branche de la session active. Le bot rafraîchit aussi la branche par défaut si nécessaire.</td>
<td>Après confirmation, exécuter un Git <code>pull</code> depuis <code>origin</code> pour la branche de la session active. Le bot rafraîchit aussi la branche par défaut si nécessaire.</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>Pousser <code>origin &lt;branch&gt;</code> pour la session active courante. Le bot demande une confirmation avant le push.</td>
<td>Exécuter un Git push vers <code>origin &lt;branch&gt;</code> pour la session active courante. Le bot demande une confirmation avant le push.</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>Afficher les cinq derniers commits Git du projet de la session active.</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>Sélectionner la branche par défaut ou courante, locale ou sur <code>origin</code>, puis confirmer un <code>git reset --hard</code>. Les cibles distantes sont d’abord pullées.</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>確認後に、アクティブなセッションのブランチで <code>origin</code> から pull します。必要に応じてデフォルト ブランチも更新します。</td>
<td>確認後に、アクティブなセッションのブランチで <code>origin</code> から Git pull します。必要に応じてデフォルト ブランチも更新します。</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>現在の アクティブなセッション に対して <code>origin &lt;branch&gt;</code> を push します。push 前に bot が確認します。</td>
<td>現在の アクティブなセッション に対して <code>origin &lt;branch&gt;</code> へ Git push します。push 前に bot が確認します。</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>アクティブなセッションの project で最新の Git コミット 5 件を表示します。</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>local または <code>origin</code> のデフォルト/現在のブランチを選択し、<code>git reset --hard</code> を確認します。remote の対象は先に pull されます。</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,19 @@ https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>확인 후 활성 세션 브랜치에 대해 <code>origin</code> 에서 pull 합니다. 필요하면 기본 브랜치도 함께 새로고칩니다.</td>
<td>확인 후 활성 세션 브랜치에 대해 <code>origin</code> 에서 Git pull 합니다. 필요하면 기본 브랜치도 함께 새로고칩니다.</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>현재 활성 세션 에 대해 <code>origin &lt;branch&gt;</code> 를 push 합니다. push 전에 bot 이 확인합니다.</td>
<td>현재 활성 세션 에 대해 <code>origin &lt;branch&gt;</code> 로 Git push 합니다. push 전에 bot 이 확인합니다.</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>활성 세션 project 의 최근 Git 커밋 5개를 표시합니다.</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>local 또는 <code>origin</code> 의 기본/현재 브랜치를 선택한 뒤 <code>git reset --hard</code> 를 확인합니다. remote 대상은 먼저 pull 합니다.</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,19 @@ The bot currently accepts:
</tr>
<tr>
<td><code>/pull</code></td>
<td>Pull from <code>origin</code> for the active session branch after confirmation. The bot also refreshes the default branch when applicable.</td>
<td>Git pull from <code>origin</code> for the active session branch after confirmation. The bot also refreshes the default branch when applicable.</td>
</tr>
<tr>
<td><code>/push</code></td>
<td>Push <code>origin &lt;branch&gt;</code> for the current active session. The bot asks for confirmation before pushing.</td>
<td>Git push <code>origin &lt;branch&gt;</code> for the current active session. The bot asks for confirmation before pushing.</td>
</tr>
<tr>
<td><code>/log</code></td>
<td>Show the top five Git commits for the active session project.</td>
</tr>
<tr>
<td><code>/reset</code></td>
<td>Select a local or <code>origin</code> default/current branch, then confirm a <code>git reset --hard</code>. Remote targets are pulled first.</td>
</tr>
<tr>
<td><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ De bot accepteert momenteel:
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>Voer na bevestiging een pull uit vanaf <code>origin</code> voor de branch van de actieve sessie. De bot ververst ook de standaardbranch wanneer dat van toepassing is.</td>
<td>Voer na bevestiging een Git pull uit vanaf <code>origin</code> voor de branch van de actieve sessie. De bot ververst ook de standaardbranch wanneer dat van toepassing is.</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>Push <code>origin &lt;branch&gt;</code> voor de huidige actieve sessie. De bot vraagt om bevestiging voordat hij pusht.</td>
<td>Voer een Git push uit naar <code>origin &lt;branch&gt;</code> voor de huidige actieve sessie. De bot vraagt om bevestiging voordat hij pusht.</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>Toon de laatste vijf Git-commits voor het project van de actieve sessie.</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>Selecteer de lokale of <code>origin</code>-standaard-/huidige branch en bevestig daarna een <code>git reset --hard</code>. Remote doelen worden eerst gepulld.</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.th.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>ดึงจาก <code>origin</code> สำหรับ branch ของเซสชันที่ใช้งานอยู่หลังจากยืนยันแล้ว และ bot จะรีเฟรช default branch ให้ด้วยเมื่อเกี่ยวข้อง</td>
<td>Git pull จาก <code>origin</code> สำหรับ branch ของเซสชันที่ใช้งานอยู่หลังจากยืนยันแล้ว และ bot จะรีเฟรช default branch ให้ด้วยเมื่อเกี่ยวข้อง</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>push <code>origin &lt;branch&gt;</code> สำหรับ เซสชันที่ใช้งานอยู่ ปัจจุบัน โดยบอตจะขอการยืนยันก่อน push</td>
<td>Git push ไปยัง <code>origin &lt;branch&gt;</code> สำหรับ เซสชันที่ใช้งานอยู่ ปัจจุบัน โดยบอตจะขอการยืนยันก่อน push</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>แสดง Git commit 5 รายการล่าสุดของ project ในเซสชันที่ใช้งานอยู่</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>เลือก default/current branch จาก local หรือ <code>origin</code> แล้วจึงยืนยัน <code>git reset --hard</code> โดยจะ pull เป้าหมาย remote ก่อน</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ Hiện tại bot chấp nhận:
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>Sau khi xác nhận, thực hiện pull từ <code>origin</code> cho branch của phiên đang hoạt động. Bot cũng làm mới branch mặc định khi cần.</td>
<td>Sau khi xác nhận, thực hiện Git pull từ <code>origin</code> cho branch của phiên đang hoạt động. Bot cũng làm mới branch mặc định khi cần.</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>Push <code>origin &lt;branch&gt;</code> cho phiên hoạt động hiện tại. Bot sẽ hỏi xác nhận trước khi push.</td>
<td>Thực hiện Git push đến <code>origin &lt;branch&gt;</code> cho phiên hoạt động hiện tại. Bot sẽ hỏi xác nhận trước khi push.</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>Hiển thị năm commit Git mới nhất của project trong phiên đang hoạt động.</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>Chọn branch mặc định/hiện tại ở local hoặc <code>origin</code>, sau đó xác nhận <code>git reset --hard</code>. Mục tiêu remote sẽ được pull trước.</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,19 @@ bot 当前接受:
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>确认后,从 <code>origin</code> 拉取活动会话当前分支。适用时,bot 也会一并刷新默认分支。</td>
<td>确认后,通过 Git 从 <code>origin</code> 拉取活动会话当前分支。适用时,bot 也会一并刷新默认分支。</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>为当前活动会话执行 <code>origin &lt;branch&gt;</code> push。push 前 bot 会要求确认。</td>
<td>为当前活动会话通过 Git push 到 <code>origin &lt;branch&gt;</code>。push 前 bot 会要求确认。</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>显示活动会话项目最近的五条 Git 提交。</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>选择 local 或 <code>origin</code> 上的默认/当前分支,然后确认执行 <code>git reset --hard</code>。远程目标会先被拉取。</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.zh-HK.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,19 @@ bot 目前接受:
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>確認後,從 <code>origin</code> 拉取作用中工作階段目前的分支。適用時,bot 也會一併重新整理預設分支。</td>
<td>確認後,透過 Git 從 <code>origin</code> 拉取作用中工作階段目前的分支。適用時,bot 也會一併重新整理預設分支。</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>為目前作用中工作階段執行 <code>origin &lt;branch&gt;</code> push。push 前 bot 會要求確認。</td>
<td>為目前作用中工作階段透過 Git push 至 <code>origin &lt;branch&gt;</code>。push 前 bot 會要求確認。</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>顯示作用中工作階段專案最近的五個 Git 提交。</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>選擇 local 或 <code>origin</code> 上的預設/目前分支,然後確認執行 <code>git reset --hard</code>。遠端目標會先被拉取。</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
12 changes: 10 additions & 2 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,19 @@ bot 目前接受:
</tr>
<tr>
<td width="332"><code>/pull</code></td>
<td>確認後,從 <code>origin</code> 拉取作用中工作階段目前的分支。適用時,bot 也會一併重新整理預設分支。</td>
<td>確認後,透過 Git 從 <code>origin</code> 拉取作用中工作階段目前的分支。適用時,bot 也會一併重新整理預設分支。</td>
</tr>
<tr>
<td width="332"><code>/push</code></td>
<td>為目前作用中工作階段執行 <code>origin &lt;branch&gt;</code> push。push 前 bot 會要求確認。</td>
<td>為目前作用中工作階段透過 Git push 至 <code>origin &lt;branch&gt;</code>。push 前 bot 會要求確認。</td>
</tr>
<tr>
<td width="332"><code>/log</code></td>
<td>顯示作用中工作階段專案最近的五個 Git 提交。</td>
</tr>
<tr>
<td width="332"><code>/reset</code></td>
<td>選擇 local 或 <code>origin</code> 上的預設/目前分支,然後確認執行 <code>git reset --hard</code>。遠端目標會先被拉取。</td>
</tr>
<tr>
<td width="332"><code>/abort</code></td>
Expand Down
20 changes: 15 additions & 5 deletions src/coding_agent_telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def default_bot_commands(*, enable_commit_command: bool, locale: str = DEFAULT_L
commands.append(BotCommand("commit", translate(locale, "bot.command.commit")))
commands.append(BotCommand("pull", translate(locale, "bot.command.pull")))
commands.append(BotCommand("push", translate(locale, "bot.command.push")))
commands.append(BotCommand("log", translate(locale, "bot.command.log")))
commands.append(BotCommand("reset", translate(locale, "bot.command.reset")))
commands.append(BotCommand("abort", translate(locale, "bot.command.abort")))
return commands

Expand Down Expand Up @@ -164,6 +166,8 @@ async def log_incoming_private_message(update, _context) -> None:
app.add_handler(CommandHandler("commit", router.handle_commit, filters=allowed_private))
app.add_handler(CommandHandler("pull", router.handle_pull, filters=allowed_private))
app.add_handler(CommandHandler("push", router.handle_push, filters=allowed_private))
app.add_handler(CommandHandler("log", router.handle_log, filters=allowed_private))
app.add_handler(CommandHandler("reset", router.handle_reset, filters=allowed_private))
app.add_handler(CommandHandler("abort", router.handle_abort, filters=allowed_private))
app.add_handler(
CallbackQueryHandler(
Expand All @@ -179,12 +183,18 @@ async def log_incoming_private_message(update, _context) -> None:
app.add_handler(CallbackQueryHandler(router.handle_long_gap_callback, pattern=r"^longgap:(compact|proceed|switch)$", block=False))
app.add_handler(CallbackQueryHandler(router.handle_branch_source_callback, pattern=r"^branchsource:[0-9a-f]{12}$", block=False))
app.add_handler(CallbackQueryHandler(router.handle_branch_discrepancy_callback, pattern=r"^branchdiscrepancy:(stored|current)$", block=False))
app.add_handler(CallbackQueryHandler(router.handle_commit_generate_callback, pattern=r"^commitgen:(confirm|cancel)$"))
app.add_handler(CallbackQueryHandler(router.handle_commit_execute_callback, pattern=r"^commitexec:(confirm|cancel)$"))
app.add_handler(CallbackQueryHandler(router.handle_diff_callback, pattern=r"^diff(?:show|page):\d+$"))
app.add_handler(CallbackQueryHandler(router.handle_commit_generate_callback, pattern=r"^commitgen:(confirm|cancel):[0-9a-f]{12}$"))
app.add_handler(CallbackQueryHandler(router.handle_commit_execute_callback, pattern=r"^commitexec:(confirm|cancel):[0-9a-f]{12}$"))
app.add_handler(CallbackQueryHandler(router.handle_diff_callback, pattern=r"^diff(?:show|page):[0-9a-f]{12}:\d+$"))
app.add_handler(CallbackQueryHandler(router.handle_switch_page_callback, pattern=r"^switchpage:\d+$"))
app.add_handler(CallbackQueryHandler(router.handle_pull_callback, pattern=r"^pull:(confirm|cancel)$"))
app.add_handler(CallbackQueryHandler(router.handle_push_callback, pattern=r"^push:(confirm|cancel)$"))
app.add_handler(CallbackQueryHandler(router.handle_pull_callback, pattern=r"^pull:(confirm|cancel):[0-9a-f]{12}$"))
app.add_handler(CallbackQueryHandler(router.handle_push_callback, pattern=r"^push:(confirm|cancel):[0-9a-f]{12}$"))
app.add_handler(
CallbackQueryHandler(
router.handle_reset_callback,
pattern=r"^reset:(?:select:[0-9a-f]{12}:(?:local|origin)-(?:default|current)|(?:confirm|cancel):[0-9a-f]{12})$",
)
)
app.add_handler(CallbackQueryHandler(router.handle_trust_project_callback, pattern=r"^trustproject:(yes|no):"))
app.add_handler(MessageHandler(allowed_private & tg_filters.PHOTO, router.handle_photo, block=False))
app.add_handler(MessageHandler(allowed_private & tg_filters.AUDIO, router.handle_audio, block=False))
Expand Down
42 changes: 24 additions & 18 deletions src/coding_agent_telegram/diff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,33 @@ def _git(project_path: Path, args: list[str]) -> str:
return proc.stdout


def _parse_status_paths(output: str) -> list[str]:
paths: list[str] = []
for line in output.splitlines():
if len(line) < 4:
def _parse_status_entries(output: str) -> list[tuple[str, str]]:
"""Parse ``git status --porcelain=v1 -z`` without losing path characters."""
records = output.split("\0")
entries: list[tuple[str, str]] = []
index = 0
while index < len(records):
record = records[index]
index += 1
if len(record) < 4:
continue
path = line[3:].strip()
if " -> " in path:
path = path.split(" -> ", 1)[1].strip()
status = record[:2]
path = record[3:]
if "R" in status or "C" in status:
# In -z mode the destination is in this record and the source path
# follows as a second NUL-terminated record.
index += 1
if path:
paths.append(path)
return paths
entries.append((status, path))
return entries


def _parse_status_paths(output: str) -> list[str]:
return [path for _status, path in _parse_status_entries(output)]


def changed_files(project_path: Path) -> list[str]:
output = _git(project_path, ["status", "--short", "--untracked-files=all"])
output = _git(project_path, ["status", "--porcelain=v1", "-z", "--untracked-files=all"])
return [
path
for path in _parse_status_paths(output)
Expand All @@ -234,16 +246,10 @@ def changed_files(project_path: Path) -> list[str]:


def split_changed_files(project_path: Path) -> tuple[list[str], list[str]]:
output = _git(project_path, ["status", "--short", "--untracked-files=all"])
output = _git(project_path, ["status", "--porcelain=v1", "-z", "--untracked-files=all"])
tracked: list[str] = []
untracked: list[str] = []
for line in output.splitlines():
if len(line) < 4:
continue
status = line[:2]
path = line[3:].strip()
if " -> " in path:
path = path.split(" -> ", 1)[1].strip()
for status, path in _parse_status_entries(output):
if (
not path
or path.startswith(f"{INTERNAL_APP_DIR}/")
Expand Down
Loading
Loading