mpfaffenberger / mpfaffenberger/code_puppy

Custom-command help parsing duplicated (and already diverged) between command_handler and SlashCompleter

Open
#425 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
814
Forks
278
Avg merge
2d 5h
Merged PRs (30d)
76

Description

Problem

get_commands_help() in code_puppy/command_line/command_handler.py:40-66 and SlashCompleter.get_completions() in prompt_toolkit_completion.py:432-477 independently re-implement the same multi-format parsing of on_custom_command_help() results (tuple-of-2, list-of-tuples, legacy list-of-strings):

command_handler.py:44-65:

if isinstance(res, tuple) and len(res) == 2:
    ...
elif isinstance(res, list):
    if res and isinstance(res[0], tuple) and len(res[0]) == 2:
        ...
    elif res and isinstance(res[0], str) and res[0].startswith("/"):
        ...  # legacy "name - desc" string parsing

prompt_toolkit_completion.py:439-470 repeats the tuple/list handling (and silently dropped the legacy string format, so a plugin using the old format shows up in /help but not in slash completions — divergence already happened).

Beyond DRY, the type-sniffing itself violates "There should be one obvious way to do it": the custom_command_help hook contract allows three return shapes, forcing every consumer to play duck-typing roulette.

There is also a related dispatch redundancy in handle_command() (lines 188-199 vs 235-270): registered-command lookup happens at the top, then ~50 lines of commented-out "legacy fallback" scaffolding (lines 202-233) remain in the file as instructional dead weight.

Suggested fix

  1. Add one normalizer next to the hook definition, e.g. in callbacks.py:
    def normalized_custom_command_help() -> list[tuple[str, str]]:
        """Flatten all on_custom_command_help() results to (name, description) pairs."""
    
    and use it from both get_commands_help() and SlashCompleter — the legacy string format then works (or is deprecated) in both places consistently.
  2. Trim the legacy-fallback comment block in handle_command to a 3-line pointer; 30+ lines of example scaffolding belongs in CONTRIBUTING.md, not in the dispatcher.

Filed by Zen Reviewer C (code-puppy-60635a)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with code_puppy/command_line/command_handler.py:40-66 and prompt_toolkit_completion.py:432-477, then inspect the custom-command help hook in callbacks.py. Trace the three documented return shapes and update both consumers to use one normalization path. Confirm legacy string results appear consistently in help and slash completions, and reduce the legacy-fallback block in handle_command() to the requested short pointer.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, developer-experience
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.