Skip to content

The agent that grows with you

fix(cli): don't crash the TUI on /queue rm with an invalid index

b13kjack838b8f4822e9
diff --git a/hermes_cli/cli_loops_mixin.py b/hermes_cli/cli_loops_mixin.py
index 9ba2a1044c0..7b7a6838b77 100644
--- a/hermes_cli/cli_loops_mixin.py
+++ b/hermes_cli/cli_loops_mixin.py
@@ -349,7 +349,16 @@ class CLILoopsMixin:
def _queue_remove(self, rest: str) -> None:
from cli import _cprint
- idx = int(rest)
+ # ``_cmd_queue`` routes a bare ``/queue rm`` here as management (its
+ # ``not rest`` fallback), and an index verb with trailing words
+ # (``rm 2 extra``) as management too, so ``rest`` is not always a bare
+ # integer. Parse the leading token instead of trusting the whole string,
+ # or int() raises out of the slash handler and kills the TUI.
+ bits = rest.split()
+ if len(bits) != 1 or not bits[0].isdigit():
+ _cprint(f" {t('cli.queue.usage_remove')}")
+ return
+ idx = int(bits[0])
removed: list = []
before, _ = self._mutate_pending_input(
lambda items: (removed.append(items.pop(idx - 1)) or items) if 1 <= idx <= len(items) else items)
diff --git a/locales/af.yaml b/locales/af.yaml
index 67d57996960..e52447c9d50 100644
--- a/locales/af.yaml
+++ b/locales/af.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Tou-item {index} verwyder: {preview}"
item_not_found: "Tou-item {index} nie gevind nie. Huidige grootte: {size}"
usage_edit: "Gebruik: /queue edit <number> <new prompt>"
+ usage_remove: "Gebruik: /queue rm <number>"
updated: "Tou-item {index} opgedateer: {preview}"
usage_move: "Gebruik: /queue move <from> <to>"
move_out_of_range: "Tou-verplasing buite bereik. Huidige grootte: {size}"
diff --git a/locales/ar.yaml b/locales/ar.yaml
index 74bb44a5d0d..505ae707c17 100644
--- a/locales/ar.yaml
+++ b/locales/ar.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "أُزيل العنصر {index} من قائمة الانتظار: {preview}"
item_not_found: "العنصر {index} غير موجود في قائمة الانتظار. الحجم الحالي: {size}"
usage_edit: "الاستخدام: /queue edit <number> <new prompt>"
+ usage_remove: "الاستخدام: /queue rm <number>"
updated: "حُدّث العنصر {index} في قائمة الانتظار: {preview}"
usage_move: "الاستخدام: /queue move <from> <to>"
move_out_of_range: "النقل خارج نطاق قائمة الانتظار. الحجم الحالي: {size}"
diff --git a/locales/de.yaml b/locales/de.yaml
index 17daf0887bf..958d77ce307 100644
--- a/locales/de.yaml
+++ b/locales/de.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Warteschlangeneintrag {index} entfernt: {preview}"
item_not_found: "Warteschlangeneintrag {index} nicht gefunden. Aktuelle Größe: {size}"
usage_edit: "Verwendung: /queue edit <number> <new prompt>"
+ usage_remove: "Verwendung: /queue rm <number>"
updated: "Warteschlangeneintrag {index} aktualisiert: {preview}"
usage_move: "Verwendung: /queue move <from> <to>"
move_out_of_range: "Verschiebung außerhalb der Warteschlange. Aktuelle Größe: {size}"
diff --git a/locales/en.yaml b/locales/en.yaml
index 6ad2ce5660a..ebd98cb8995 100644
--- a/locales/en.yaml
+++ b/locales/en.yaml
@@ -2455,6 +2455,7 @@ cli:
removed: "Removed queue item {index}: {preview}"
item_not_found: "Queue item {index} not found. Current size: {size}"
usage_edit: "Usage: /queue edit <number> <new prompt>"
+ usage_remove: "Usage: /queue rm <number>"
updated: "Updated queue item {index}: {preview}"
usage_move: "Usage: /queue move <from> <to>"
move_out_of_range: "Queue move out of range. Current size: {size}"
diff --git a/locales/es.yaml b/locales/es.yaml
index c03a504214a..8d5ca9268d0 100644
--- a/locales/es.yaml
+++ b/locales/es.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Se eliminó el elemento {index} de la cola: {preview}"
item_not_found: "No se encontró el elemento {index} de la cola. Tamaño actual: {size}"
usage_edit: "Uso: /queue edit <número> <nuevo prompt>"
+ usage_remove: "Uso: /queue rm <number>"
updated: "Se actualizó el elemento {index} de la cola: {preview}"
usage_move: "Uso: /queue move <desde> <hasta>"
move_out_of_range: "Movimiento fuera de rango en la cola. Tamaño actual: {size}"
diff --git a/locales/fr.yaml b/locales/fr.yaml
index f690f1f3d71..5337c6afea7 100644
--- a/locales/fr.yaml
+++ b/locales/fr.yaml
@@ -2628,6 +2628,7 @@ cli:
removed: "Élément {index} retiré de la file : {preview}"
item_not_found: "Élément {index} introuvable dans la file. Taille actuelle : {size}"
usage_edit: "Usage : /queue edit <number> <new prompt>"
+ usage_remove: "Usage : /queue rm <number>"
updated: "Élément {index} de la file mis à jour : {preview}"
usage_move: "Usage : /queue move <from> <to>"
move_out_of_range: "Déplacement hors limites de la file. Taille actuelle : {size}"
diff --git a/locales/ga.yaml b/locales/ga.yaml
index 4373cc95055..baf6a08747c 100644
--- a/locales/ga.yaml
+++ b/locales/ga.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Baineadh mír scuaine {index}: {preview}"
item_not_found: "Níor aimsíodh mír scuaine {index}. Méid reatha: {size}"
usage_edit: "Úsáid: /queue edit <number> <new prompt>"
+ usage_remove: "Úsáid: /queue rm <number>"
updated: "Nuashonraíodh mír scuaine {index}: {preview}"
usage_move: "Úsáid: /queue move <from> <to>"
move_out_of_range: "Bogadh scuaine as raon. Méid reatha: {size}"
diff --git a/locales/hu.yaml b/locales/hu.yaml
index 4551b1a3455..a39bcfdd94e 100644
--- a/locales/hu.yaml
+++ b/locales/hu.yaml
@@ -2372,6 +2372,7 @@ cli:
removed: "A(z) {index}. sorelem eltávolítva: {preview}"
item_not_found: "A(z) {index}. sorelem nem található. Jelenlegi méret: {size}"
usage_edit: "Használat: /queue edit <number> <new prompt>"
+ usage_remove: "Használat: /queue rm <number>"
updated: "A(z) {index}. sorelem frissítve: {preview}"
usage_move: "Használat: /queue move <from> <to>"
move_out_of_range: "A mozgatás kívül esik a soron. Jelenlegi méret: {size}"
diff --git a/locales/it.yaml b/locales/it.yaml
index 058997415df..386c280087c 100644
--- a/locales/it.yaml
+++ b/locales/it.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Rimosso l'elemento {index} della coda: {preview}"
item_not_found: "Elemento {index} della coda non trovato. Dimensione attuale: {size}"
usage_edit: "Uso: /queue edit <number> <new prompt>"
+ usage_remove: "Uso: /queue rm <number>"
updated: "Aggiornato l'elemento {index} della coda: {preview}"
usage_move: "Uso: /queue move <from> <to>"
move_out_of_range: "Spostamento fuori dai limiti della coda. Dimensione attuale: {size}"
diff --git a/locales/ja.yaml b/locales/ja.yaml
index 26fd0e9f33f..59a001f66ca 100644
--- a/locales/ja.yaml
+++ b/locales/ja.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "キュー項目 {index} を削除しました: {preview}"
item_not_found: "キュー項目 {index} が見つかりません。現在のサイズ: {size}"
usage_edit: "使い方: /queue edit <number> <new prompt>"
+ usage_remove: "使い方: /queue rm <number>"
updated: "キュー項目 {index} を更新しました: {preview}"
usage_move: "使い方: /queue move <from> <to>"
move_out_of_range: "キューの移動先が範囲外です。現在のサイズ: {size}"
diff --git a/locales/ko.yaml b/locales/ko.yaml
index 3d8ead328c9..3f3c601feff 100644
--- a/locales/ko.yaml
+++ b/locales/ko.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "대기열 항목 {index}을(를) 제거했어요: {preview}"
item_not_found: "대기열 항목 {index}을(를) 찾을 수 없어요. 현재 크기: {size}"
usage_edit: "사용법: /queue edit <number> <new prompt>"
+ usage_remove: "사용법: /queue rm <number>"
updated: "대기열 항목 {index}을(를) 수정했어요: {preview}"
usage_move: "사용법: /queue move <from> <to>"
move_out_of_range: "대기열 이동 범위를 벗어났어요. 현재 크기: {size}"
diff --git a/locales/pt.yaml b/locales/pt.yaml
index 5d0168ac298..8cef4f434d3 100644
--- a/locales/pt.yaml
+++ b/locales/pt.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Item {index} removido da fila: {preview}"
item_not_found: "Item {index} da fila não encontrado. Tamanho atual: {size}"
usage_edit: "Uso: /queue edit <número> <novo prompt>"
+ usage_remove: "Uso: /queue rm <number>"
updated: "Item {index} da fila atualizado: {preview}"
usage_move: "Uso: /queue move <origem> <destino>"
move_out_of_range: "Movimento na fila fora do intervalo. Tamanho atual: {size}"
diff --git a/locales/ru.yaml b/locales/ru.yaml
index 5ce84d87ce1..bf680543477 100644
--- a/locales/ru.yaml
+++ b/locales/ru.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Удалён элемент очереди {index}: {preview}"
item_not_found: "Элемент очереди {index} не найден. Текущий размер: {size}"
usage_edit: "Использование: /queue edit <номер> <новый промпт>"
+ usage_remove: "Использование: /queue rm <number>"
updated: "Обновлён элемент очереди {index}: {preview}"
usage_move: "Использование: /queue move <откуда> <куда>"
move_out_of_range: "Перемещение выходит за границы очереди. Текущий размер: {size}"
diff --git a/locales/tr.yaml b/locales/tr.yaml
index 16296eaf7f2..910ca95f6bb 100644
--- a/locales/tr.yaml
+++ b/locales/tr.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Kuyruk öğesi {index} kaldırıldı: {preview}"
item_not_found: "Kuyruk öğesi {index} bulunamadı. Geçerli boyut: {size}"
usage_edit: "Kullanım: /queue edit <number> <new prompt>"
+ usage_remove: "Kullanım: /queue rm <number>"
updated: "Kuyruk öğesi {index} güncellendi: {preview}"
usage_move: "Kullanım: /queue move <from> <to>"
move_out_of_range: "Kuyruk taşıma aralık dışında. Geçerli boyut: {size}"
diff --git a/locales/uk.yaml b/locales/uk.yaml
index 30628dd17b9..593b3300740 100644
--- a/locales/uk.yaml
+++ b/locales/uk.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "Видалено елемент черги {index}: {preview}"
item_not_found: "Елемент черги {index} не знайдено. Поточний розмір: {size}"
usage_edit: "Використання: /queue edit <number> <new prompt>"
+ usage_remove: "Використання: /queue rm <number>"
updated: "Оновлено елемент черги {index}: {preview}"
usage_move: "Використання: /queue move <from> <to>"
move_out_of_range: "Переміщення в черзі поза межами діапазону. Поточний розмір: {size}"
diff --git a/locales/zh-hant.yaml b/locales/zh-hant.yaml
index ba0e2b8e247..4383ca2edc8 100644
--- a/locales/zh-hant.yaml
+++ b/locales/zh-hant.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "已移除佇列項目 {index}:{preview}"
item_not_found: "找不到佇列項目 {index}。目前佇列長度:{size}"
usage_edit: "用法:/queue edit <number> <new prompt>"
+ usage_remove: "用法:/queue rm <number>"
updated: "已更新佇列項目 {index}:{preview}"
usage_move: "用法:/queue move <from> <to>"
move_out_of_range: "佇列移動超出範圍。目前佇列長度:{size}"
diff --git a/locales/zh.yaml b/locales/zh.yaml
index 8f5bec8a220..92b79dc27b1 100644
--- a/locales/zh.yaml
+++ b/locales/zh.yaml
@@ -2355,6 +2355,7 @@ cli:
removed: "已移除队列项 {index}:{preview}"
item_not_found: "未找到队列项 {index}。当前队列长度:{size}"
usage_edit: "用法:/queue edit <number> <new prompt>"
+ usage_remove: "用法:/queue rm <number>"
updated: "已更新队列项 {index}:{preview}"
usage_move: "用法:/queue move <from> <to>"
move_out_of_range: "队列移动位置超出范围。当前队列长度:{size}"
diff --git a/tests/hermes_cli/test_cli_init.py b/tests/hermes_cli/test_cli_init.py
index 2861610e9a7..b2bb3cb58ad 100644
--- a/tests/hermes_cli/test_cli_init.py
+++ b/tests/hermes_cli/test_cli_init.py
@@ -168,6 +168,21 @@ class TestBusyInputMode:
cli.process_command("/queue move 1 9")
assert cli._pending_input_items() == ["only item"]
+ def test_queue_rm_without_index_prints_usage_instead_of_raising(self):
+ """``/queue rm`` with no index reaches _queue_remove with rest="" and used to
+ raise ValueError out of the prompt_toolkit key handler, killing the TUI."""
+ cli = _make_cli()
+ cli.process_command("/queue first prompt")
+ cli.process_command("/queue rm")
+ assert cli._pending_input_items() == ["first prompt"]
+
+ def test_queue_rm_with_trailing_words_prints_usage_instead_of_raising(self):
+ """``rest`` is only known to start with a digit, so "2 extra" reached int()."""
+ cli = _make_cli()
+ cli.process_command("/queue first prompt")
+ cli.process_command("/queue rm 1 extra")
+ assert cli._pending_input_items() == ["first prompt"]
+