Skip to content

fix(cli): zsh completion fails under eval in .zshrc (#6122)#9618

Closed
mecampbellsoup wants to merge 1 commit into
NousResearch:mainfrom
mecampbellsoup:mc/fix-zsh-completion-eval
Closed

fix(cli): zsh completion fails under eval in .zshrc (#6122)#9618
mecampbellsoup wants to merge 1 commit into
NousResearch:mainfrom
mecampbellsoup:mc/fix-zsh-completion-eval

Conversation

@mecampbellsoup

Copy link
Copy Markdown

Summary

Fixes #6122. The generated zsh completion script ends with _hermes "$@", which invokes _arguments outside any completion context when the script is loaded the documented way:

# ~/.zshrc (per docs)
eval "$(hermes completion zsh)"

Shell startup then errors:

_arguments:comparguments:327: can only be called from completion function

Replace the direct call with compdef _hermes hermes so zsh registers the function with its completion system and invokes it only during completion.

Verification

  • Reproduced the original bug in a clean zsh -f by generating the pre-fix script and loading it via eval — errors as reported.
  • Verified the fix by loading the new script the same way — loads cleanly, hermes <TAB> works.
  • Added a regression test (test_zsh_completion_registers_via_compdef_not_direct_call) that asserts the generated script uses compdef _hermes hermes and does not contain _hermes "$@".

Test plan

  • pytest tests/hermes_cli/test_profiles.py -k zsh_completion — 3 passed
  • Manual: eval "$(python -c 'from hermes_cli.profiles import generate_zsh_completion; print(generate_zsh_completion())')" in zsh -f — no error
  • Manual: pre-fix script reproduces error in same clean shell

Closes #6122

)

The generated zsh completion script ended with `_hermes "$@"`, which
invokes `_arguments` outside any completion context when the script is
loaded via `eval "$(hermes completion zsh)"` in `.zshrc`. This raises:

    _arguments:comparguments:327: can only be called from completion function

on every shell startup.

Replace the direct call with `compdef _hermes hermes` so zsh registers
the function with its completion system and calls it only during
completion. Add a regression test.

Verified:
- Old script (tail `_hermes "$@"`) reproduces the error in `zsh -f`
- New script (tail `compdef _hermes hermes`) loads cleanly

Closes NousResearch#6122

@RuckVibeCodes RuckVibeCodes left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gus-first-pass] fix(cli): zsh completion fails under eval in .zshrc - Simple fix, good explanation.

@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 Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #6141 and #11754 — all three PRs fix the same zsh completion _arguments error from #6122 (trailing _hermes "$@" invocation outside completion context). #11754 also fixes an additional alias spec syntax issue.

@teknium1

Copy link
Copy Markdown
Contributor

Fixed via PR #25075 (#25075). Same root cause you identified for #6122. The patch targeted hermes_cli/profiles.py::generate_zsh_completion(), which is dead code — hermes completion zsh is wired to hermes_cli/completion.py::generate_zsh(). The salvage applies the compdef fix to the live generator and removes the dead function. Thanks for the analysis.

@teknium1 teknium1 closed this May 13, 2026
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.

Zsh completion script fails with eval: _arguments called outside completion context

4 participants