Repository navigation
fix(cli): add positional argument completion for zsh leaf commands - #69509
armorbreak001 wants to merge 1 commit into
Conversation
Greptile SummaryThis PR adds
Confidence Score: 2/5Not safe to merge — three P1 bugs cause runtime errors and broken zsh completions for existing commands. All three issues are present defects in the changed code: a TypeError throw during script generation (description-as-function), wrong zsh spec for variadic args, and a syntax-corrupting trailing backslash that affects all leaf commands that have options but no positional args. Together they mean the fix either crashes or silently produces broken completions for the majority of commands. src/cli/completion-cli.ts — specifically lines 231, 237–240, and 280–285. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 231
Comment:
**`description` is a string, not a function**
`Argument.description` in Commander.js is a plain string property, not a getter method. Calling `arg.description?.()` will throw `TypeError: arg.description is not a function` at runtime whenever a positional argument actually has a description string set (the `?.` short-circuits only for `null`/`undefined`, not for a non-null string value). The fallback to `arg.name` therefore never fires for described args — instead the whole completion generation crashes.
Fix: use the value directly:
```suggestion
const desc = (arg.description ?? arg.name)
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 237-240
Comment:
**Variadic branch produces identical output to non-variadic**
Both arms of the `if (arg.variadic)` check return the same string (`${n}:${desc}:_files`), so the branch is dead code. In zsh `_arguments`, a fixed positional slot uses `n:msg:action` while variadic (repeatable) slots use `*:msg:action`. Using a fixed index for a variadic arg means only the first file is ever completed; subsequent values get no completion.
```suggestion
if (arg.variadic) {
return `*:${desc}:_files`;
}
return `${n}:${desc}:_files`;
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 280-285
Comment:
**Trailing `\` produces invalid zsh syntax for commands with no positional args**
When `generateZshPositionalArgs(cmd)` returns `""` (the command has no positional arguments), the template still emits a backslash continuation from the previous line, leaving an empty continuation line followed by `}`. Zsh treats `}` as a word argument to `_arguments`, corrupting the completion function for every leaf command that has options but no positional arguments — the majority of commands.
Only emit the extra `\` and positional-args fragment when the helper returns a non-empty string:
```typescript
const positional = generateZshPositionalArgs(cmd);
segments.push(`
${funcName}() {
_arguments -C \\
${generateZshArgs(cmd)}${positional ? ` \\\n ${positional}` : ""}
}
`);
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(cli): add positional argument comple..." | Re-trigger Greptile |
| return args | ||
| .map((arg, i) => { | ||
| const n = i + 1; | ||
| const desc = (arg.description?.() ?? arg.name) |
There was a problem hiding this comment.
description is a string, not a function
Argument.description in Commander.js is a plain string property, not a getter method. Calling arg.description?.() will throw TypeError: arg.description is not a function at runtime whenever a positional argument actually has a description string set (the ?. short-circuits only for null/undefined, not for a non-null string value). The fallback to arg.name therefore never fires for described args — instead the whole completion generation crashes.
Fix: use the value directly:
| const desc = (arg.description?.() ?? arg.name) | |
| const desc = (arg.description ?? arg.name) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 231
Comment:
**`description` is a string, not a function**
`Argument.description` in Commander.js is a plain string property, not a getter method. Calling `arg.description?.()` will throw `TypeError: arg.description is not a function` at runtime whenever a positional argument actually has a description string set (the `?.` short-circuits only for `null`/`undefined`, not for a non-null string value). The fallback to `arg.name` therefore never fires for described args — instead the whole completion generation crashes.
Fix: use the value directly:
```suggestion
const desc = (arg.description ?? arg.name)
```
How can I resolve this? If you propose a fix, please make it concise.| if (arg.variadic) { | ||
| return `${n}:${desc}:_files`; | ||
| } | ||
| return `${n}:${desc}:_files`; |
There was a problem hiding this comment.
Variadic branch produces identical output to non-variadic
Both arms of the if (arg.variadic) check return the same string (${n}:${desc}:_files), so the branch is dead code. In zsh _arguments, a fixed positional slot uses n:msg:action while variadic (repeatable) slots use *:msg:action. Using a fixed index for a variadic arg means only the first file is ever completed; subsequent values get no completion.
| if (arg.variadic) { | |
| return `${n}:${desc}:_files`; | |
| } | |
| return `${n}:${desc}:_files`; | |
| if (arg.variadic) { | |
| return `*:${desc}:_files`; | |
| } | |
| return `${n}:${desc}:_files`; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 237-240
Comment:
**Variadic branch produces identical output to non-variadic**
Both arms of the `if (arg.variadic)` check return the same string (`${n}:${desc}:_files`), so the branch is dead code. In zsh `_arguments`, a fixed positional slot uses `n:msg:action` while variadic (repeatable) slots use `*:msg:action`. Using a fixed index for a variadic arg means only the first file is ever completed; subsequent values get no completion.
```suggestion
if (arg.variadic) {
return `*:${desc}:_files`;
}
return `${n}:${desc}:_files`;
```
How can I resolve this? If you propose a fix, please make it concise.| segments.push(` | ||
| ${funcName}() { | ||
| _arguments -C \\ | ||
| ${generateZshArgs(cmd)} | ||
| ${generateZshArgs(cmd)} \\ | ||
| ${generateZshPositionalArgs(cmd)} | ||
| } |
There was a problem hiding this comment.
Trailing
\ produces invalid zsh syntax for commands with no positional args
When generateZshPositionalArgs(cmd) returns "" (the command has no positional arguments), the template still emits a backslash continuation from the previous line, leaving an empty continuation line followed by }. Zsh treats } as a word argument to _arguments, corrupting the completion function for every leaf command that has options but no positional arguments — the majority of commands.
Only emit the extra \ and positional-args fragment when the helper returns a non-empty string:
const positional = generateZshPositionalArgs(cmd);
segments.push(`
${funcName}() {
_arguments -C \\
${generateZshArgs(cmd)}${positional ? ` \\\n ${positional}` : ""}
}
`);Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 280-285
Comment:
**Trailing `\` produces invalid zsh syntax for commands with no positional args**
When `generateZshPositionalArgs(cmd)` returns `""` (the command has no positional arguments), the template still emits a backslash continuation from the previous line, leaving an empty continuation line followed by `}`. Zsh treats `}` as a word argument to `_arguments`, corrupting the completion function for every leaf command that has options but no positional arguments — the majority of commands.
Only emit the extra `\` and positional-args fragment when the helper returns a non-empty string:
```typescript
const positional = generateZshPositionalArgs(cmd);
segments.push(`
${funcName}() {
_arguments -C \\
${generateZshArgs(cmd)}${positional ? ` \\\n ${positional}` : ""}
}
`);
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c016fa94d7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (arg.variadic) { | ||
| return `${n}:${desc}:_files`; | ||
| } | ||
| return `${n}:${desc}:_files`; |
There was a problem hiding this comment.
Quote positional specs before passing them to _arguments
The positional completion entries are emitted as raw words (${n}:${desc}:_files) rather than quoted _arguments specs, so any argument description containing spaces gets split into multiple shell tokens and _arguments misparses the definition. This affects many CLI arguments with multi-word descriptions (for example, "Model id or alias"), causing zsh completion to fail or behave unpredictably for those leaf commands. Emit each positional spec as a single quoted argument (or escape spaces) so zsh receives one complete spec per position.
Useful? React with 👍 / 👎.
|
Related work from PRtags group Title: Open PR duplicate: [Bug]: zsh completion for openclaw wiki ingest does not complete file paths
|
|
Closing this as duplicate or superseded after Codex automated review. Close #69509 as a duplicate of open PR #69305. Current main still lacks the zsh positional-argument completion fix, so the underlying #69293 bug remains real, but #69305 already tracks the same work with broader handling and regression tests. #69509 is a one-file duplicate with unresolved correctness findings. Best possible solution: Close #69509 as duplicate cleanup and keep the remaining work consolidated on #69305 and the linked #69293 bug. The eventual fix should emit quoted zsh positional specs from Commander argument metadata, handle optional and variadic arguments correctly, choose file/directory actions conservatively, and include regression tests in What I checked:
So I’m closing this here and keeping the remaining discussion on the canonical linked item. Codex Review notes: model gpt-5.5, reasoning high; reviewed against ee2ab9a64492. |
Summary
Zsh completion for leaf commands (e.g.
openclaw wiki ingest) was missing positional argument specs, so<Tab>did not trigger file-path completion for commands that accept file arguments.Root cause:
generateZshSubcommandsonly emitted_argumentswith option flags (generateZshArgs) for leaf commands — it never included"N:description:_files"lines for registered.argument()definitions.Changes
generateZshPositionalArgs(cmd)helper that reads argument metadata from Commander.js internal_args/registeredArguments(with fallback between the two for version compatibility) and emits zsh positional argument completion specs ("1:markdown file:_files"style)._argumentscalls.Fix
Closes #69293
Notes
_filesaction for all positional arguments since the vast majority of openclaw leaf-command args are file paths (ingest, export, import, etc.). Commands with non-file positional args (if any) would need a more sophisticated mapper in a follow-up.