Skip to content

fix(cli): tab-complete paths with embedded spaces#26299

Open
0xDevNinja wants to merge 1 commit into
NousResearch:mainfrom
0xDevNinja:fix/26223-tab-completion-spaces
Open

fix(cli): tab-complete paths with embedded spaces#26299
0xDevNinja wants to merge 1 commit into
NousResearch:mainfrom
0xDevNinja:fix/26223-tab-completion-spaces

Conversation

@0xDevNinja
Copy link
Copy Markdown
Contributor

What does this PR do?

_extract_path_word() in hermes_cli/commands.py walked back to the
nearest space, so after prompt_toolkit autocompleted a directory whose
name contained a space (e.g. ./My Documents/), pressing Tab again
extracted just Documents/. That isn't a directory in cwd, so the
listdir returned nothing and tab completion silently stopped working
for everything inside that directory.

Fix

Find the rightmost anchored prefix (./, ../, ~/, /) that sits
at the start of the line or directly after a space, and treat
everything from there to the cursor as the path. When no anchor is
present, fall back to the last space-delimited token (preserves the
existing mid-line open src/utils/x.py behaviour).

Why not the heuristic proposed in the issue body

The "keep walking past a space if the tail contains a slash" rule
over-consumes in normal prose — for tell me about ./My Documents/,
every backwards chunk contains a slash, so the walk reaches the start
of the line and the resulting "word" can never be listdir'd. The
anchor-based approach stops as soon as the captured tail can stand on
its own as a path.

Related Issue

Fixes #26223

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update
  • Code refactor / cleanup
  • Performance improvement
  • Test coverage improvement

Changes Made

  • hermes_cli/commands.py — anchor-based _extract_path_word().
  • tests/hermes_cli/test_path_completion.py — six new cases covering
    ./My Documents/, mid-sentence look at ./My Documents/, /etc/My Files/, ~/My Notes/todo.md, deep ./My Documents/Sub Folder/file.py,
    and the anchored-extension fallback for ./src/foo bar.py.

Testing

uv run pytest tests/hermes_cli/test_path_completion.py -q
# 33 passed

_extract_path_word() walked back only to the nearest space, so after
prompt_toolkit autocompleted a directory whose name contained a space
(e.g. `./My Documents/`), pressing Tab again extracted just `Documents/`
— which does not exist in the cwd — and produced no completions.

Find the rightmost anchored prefix (`./`, `../`, `~/`, `/`) that sits at
the start of the line or directly after a space, and treat everything
from there to the cursor as the path. Falls back to the last
space-delimited token when no anchor is present, preserving the existing
`open src/utils/x.py` mid-line behaviour. Avoids the over-consumption
issue with the obvious "stop at any slash in tail" heuristic, which
would walk all the way back through `tell me about ./My Documents/`.

Fixes NousResearch#26223
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels May 15, 2026
@alt-glitch
Copy link
Copy Markdown
Collaborator

Likely duplicate of #26230 — both fix _extract_path_word() space handling for #26223. This PR uses an anchor-based approach vs #26230's approach. Maintainer should pick one and close the other.

NishantEC

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Tab completion stops working after completing a directory path containing spaces

3 participants