Skip to content

The agent that grows with you

fix(gateway): /skills and /kanban with a quote in the argument are classified, not an internal error

unsupportedpastels226d854e8dce
diff --git a/gateway/session_commands.py b/gateway/session_commands.py
index bf5dd885037..2490004d23d 100644
--- a/gateway/session_commands.py
+++ b/gateway/session_commands.py
@@ -51,7 +51,12 @@ _KANBAN_READS = frozenset({'', 'help', '--help', '-h', '?', 'list', 'ls', 'show'
def _first_token(arg):
- tokens = iter(shlex.split(arg) if arg.strip() else [])
+ """/kanban's verb as its handler parses it (shlex, hermes_cli/kanban.py ``run_slash``): an unclosed
+ quote can't run there either, so it is refused by name instead of failing as an internal error."""
+ try:
+ tokens = iter(shlex.split(arg) if arg.strip() else [])
+ except ValueError as exc:
+ raise RuntimeStoreError('invalid_params', field='arg', detail=str(exc)) from None
for token in tokens:
if token == '--board':
next(tokens, None)
@@ -61,8 +66,8 @@ def _first_token(arg):
def _first_word(arg):
- """The first whitespace-separated word, as main's CLI and messaging /memory handler split it:
- a quote later in the line belongs to the argument (`/memory pending it's`)."""
+ """The first whitespace-separated word, as main's CLI and the messaging /memory and /skills
+ handlers split it: a quote later in the line belongs to the argument (`/memory pending it's`)."""
words = arg.split(None, 1)
return words[0].lower() if words else ''
@@ -71,7 +76,7 @@ def _first_word(arg):
# redeems a credit, ``/suggestions accept|catalog`` schedules cron jobs delivering to this
# (non-messaging) chat. The review queues read like main's CLI: only the first word counts.
_READ_ARGUMENTS = {
- 'skills': lambda arg: _first_token(arg) in {'', 'pending', 'diff'},
+ 'skills': lambda arg: _first_word(arg) in {'', 'pending', 'diff'},
'usage': lambda arg: not arg.strip(),
'memory': lambda arg: _first_word(arg) in {'', 'pending'},
'suggestions': lambda arg: not arg.strip(),
@@ -83,7 +88,7 @@ _READ_ARGUMENTS = {
# applied for this session's profile (`/memory` and `/skills` approve|reject their staged queues;
# `approval` updates their config.yaml switch, as main's CLI wrote it).
_CONTROL_ARGUMENTS = {
- 'skills': lambda arg: _first_token(arg) in {'approve', 'apply', 'reject', 'deny', 'drop', 'approval', 'mode'},
+ 'skills': lambda arg: _first_word(arg) in {'approve', 'apply', 'reject', 'deny', 'drop', 'approval', 'mode'},
'memory': lambda arg: _first_word(arg) in {'approve', 'apply', 'reject', 'deny', 'drop', 'approval', 'mode'},
}
diff --git a/tests/gateway/test_session_memory_review.py b/tests/gateway/test_session_memory_review.py
index a39a4586d5e..0bfb50b7c68 100644
--- a/tests/gateway/test_session_memory_review.py
+++ b/tests/gateway/test_session_memory_review.py
@@ -51,6 +51,34 @@ def test_memory_reads_only_its_first_word_like_the_cli(arg, reach):
from gateway.session_commands import command_verdict
assert command_verdict('memory', arg) == reach
+
[email protected](('arg', 'reach'), [
+ ("pending it's", 'read'), ('diff "unclosed', 'read'), ("approve it's", 'control'), ("it's pending", 'refused')])
+def test_skills_reads_only_its_first_word_like_its_handler(arg, reach):
+ """The messaging /skills handler splits on whitespace too (gateway/slash_commands.py
+ ``_handle_skills_command``): a quote later in the line is the argument's, not a parse failure."""
+ from gateway.session_commands import command_verdict
+ try:
+ verdict = command_verdict('skills', arg)
+ except ValueError as exc:
+ verdict = f'internal error: {exc}'
+ assert verdict == reach
+
+
+def test_kanban_with_an_unclosed_quote_is_refused_by_name():
+ """/kanban parses with shlex (hermes_cli/kanban.py ``run_slash``), so an unclosed quote can't run
+ there either: the client gets ``invalid_params`` naming the argument, not an internal error."""
+ from gateway.session_commands import command_verdict
+ from hermes_state_runtime import RuntimeStoreError
+ try:
+ verdict = command_verdict('kanban', "show it's")
+ except RuntimeStoreError as exc:
+ verdict = (exc.reason, exc.field)
+ except ValueError as exc:
+ verdict = f'internal error: {exc}'
+ assert verdict == ('invalid_params', 'arg')
+ assert command_verdict('kanban', 'show "two words"') == 'read'
+
def _stage(home, pending_id, content):
folder = home / 'pending' / 'memory'
folder.mkdir(parents=True, exist_ok=True)