Skip to content

fix: complete zsh positional wiki ingest paths - #69352

Closed
nnish16 wants to merge 2 commits into
openclaw:mainfrom
nnish16:fix/issue-69293
Closed

nnish16 wants to merge 2 commits into
openclaw:mainfrom
nnish16:fix/issue-69293

Conversation

@nnish16

@nnish16 nnish16 commented Apr 20, 2026

Copy link
Copy Markdown

Summary

Teach the zsh completion generator to emit positional argument specs for leaf commands, including _files completion for path-like arguments. This restores tab completion for openclaw wiki ingest <path> without changing unrelated completion behavior.

Changes

  • add reusable escaping for zsh completion descriptions
  • emit zsh positional argument specs from Commander registered arguments
  • route path-like positional arguments to _files
  • add a regression test covering openclaw wiki ingest <path>

Testing

  • pnpm exec vitest run src/cli/completion-cli.test.ts src/cli/completion-cli.write-state.test.ts

Fixes #69293

Copilot AI review requested due to automatic review settings April 20, 2026 13:53
@greptile-apps

greptile-apps Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds positional argument completion to the zsh completion generator by extracting a reusable escapeZshDescription helper, introducing generateZshArgumentAction (which routes path-like args to _files), and wiring positional specs into the leaf-command _arguments call. The regression test for openclaw wiki ingest <path> covers the primary fix correctly.

Confidence Score: 5/5

Safe to merge — the fix is narrowly scoped, well-tested, and all remaining findings are P2 style suggestions that do not affect the stated fix.

No P0 or P1 issues found. The optional-positional indexing gap (using :: without a position number) only matters when a command has multiple optional positionals, which is not the case for any command fixed here. All other observations are cosmetic.

No files require special attention.

Comments Outside Diff (1)

  1. src/cli/completion-cli.ts, line 230-243 (link)

    P2 generateZshSubcmdList still uses inline escaping

    escapeZshDescription was extracted for reuse but generateZshSubcmdList retains its own inline escape chain (missing the " → \" replacement). The difference is intentional because it uses single-quoted shell strings, so double-quotes don't need escaping there, but a brief comment noting the difference would prevent a future reader from mistakenly "fixing" it by calling escapeZshDescription (which would over-escape).

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/cli/completion-cli.ts
    Line: 230-243
    
    Comment:
    **`generateZshSubcmdList` still uses inline escaping**
    
    `escapeZshDescription` was extracted for reuse but `generateZshSubcmdList` retains its own inline escape chain (missing the `"` → `\"` replacement). The difference is intentional because it uses single-quoted shell strings, so double-quotes don't need escaping there, but a brief comment noting the difference would prevent a future reader from mistakenly "fixing" it by calling `escapeZshDescription` (which would over-escape).
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 223

Comment:
**Optional positional uses `::` without a position index**

For optional non-variadic args, `"::"` is emitted without a position number. In zsh `_arguments`, the correct format for an *Nth optional positional* is `N::message:action` — omitting `N` makes it a free-floating "optional extra arg" spec rather than a position-bound one. For the current `<path>` fix this is a required arg (`1:`) so there's no impact, but if a future command registers multiple optional positional arguments the later ones will not bind to the right positions.

```suggestion
      const position = arg.variadic ? "*::" : arg.required ? `${index + 1}:` : `${index + 1}::`;
```

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: 230-243

Comment:
**`generateZshSubcmdList` still uses inline escaping**

`escapeZshDescription` was extracted for reuse but `generateZshSubcmdList` retains its own inline escape chain (missing the `"` → `\"` replacement). The difference is intentional because it uses single-quoted shell strings, so double-quotes don't need escaping there, but a brief comment noting the difference would prevent a future reader from mistakenly "fixing" it by calling `escapeZshDescription` (which would over-escape).

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix: complete zsh positional wiki ingest..." | Re-trigger Greptile

Comment thread src/cli/completion-cli.ts Outdated
return cmd.registeredArguments
.map((arg, index) => {
const description = escapeZshDescription(arg.description || arg.name());
const position = arg.variadic ? "*::" : arg.required ? `${index + 1}:` : "::";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Optional positional uses :: without a position index

For optional non-variadic args, "::" is emitted without a position number. In zsh _arguments, the correct format for an Nth optional positional is N::message:action — omitting N makes it a free-floating "optional extra arg" spec rather than a position-bound one. For the current <path> fix this is a required arg (1:) so there's no impact, but if a future command registers multiple optional positional arguments the later ones will not bind to the right positions.

Suggested change
const position = arg.variadic ? "*::" : arg.required ? `${index + 1}:` : "::";
const position = arg.variadic ? "*::" : arg.required ? `${index + 1}:` : `${index + 1}::`;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 223

Comment:
**Optional positional uses `::` without a position index**

For optional non-variadic args, `"::"` is emitted without a position number. In zsh `_arguments`, the correct format for an *Nth optional positional* is `N::message:action` — omitting `N` makes it a free-floating "optional extra arg" spec rather than a position-bound one. For the current `<path>` fix this is a required arg (`1:`) so there's no impact, but if a future command registers multiple optional positional arguments the later ones will not bind to the right positions.

```suggestion
      const position = arg.variadic ? "*::" : arg.required ? `${index + 1}:` : `${index + 1}::`;
```

How can I resolve this? If you propose a fix, please make it concise.

@nnish16 nnish16 Apr 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in commit f902855: optional non-variadic positionals now emit indexed N:: specs so later optional args stay position-bound.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the zsh completion generator so it emits positional-argument specs for leaf commands (including _files completion for path-like args), restoring tab completion for openclaw wiki ingest <path>.

Changes:

  • Refactors zsh description escaping into a reusable helper.
  • Generates zsh positional argument specs from Commander registered arguments, routing path-like args to _files.
  • Adds a regression test covering nested leaf command positional path completion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/cli/completion-cli.ts Adds zsh positional argument spec generation and _files actions; refactors escaping helper.
src/cli/completion-cli.test.ts Adds regression coverage for wiki ingest <path> positional completion.

Comment thread src/cli/completion-cli.ts
return value
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"')
.replace(/'/g, "'\\''")

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

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

escapeZshDescription() is used for positional argument descriptions in generateZshPositionals(), but it does not escape :. In zsh _arguments specs, : is a field separator, so a description containing a colon (e.g. "Auth profile ids (e.g. anthropic:default)" in src/cli/models-cli.ts) will break parsing/completion. Please escape literal colons (e.g. replace : with \:) when emitting positional specs (either in escapeZshDescription or specifically for positional descriptions).

Suggested change
.replace(/'/g, "'\\''")
.replace(/'/g, "'\\''")
.replace(/:/g, "\\:")

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in commit f902855: zsh positional descriptions now escape literal colons before being inserted into _arguments specs.

Comment thread src/cli/completion-cli.ts Outdated
return cmd.registeredArguments
.map((arg, index) => {
const description = escapeZshDescription(arg.description || arg.name());
const position = arg.variadic ? "*::" : arg.required ? `${index + 1}:` : "::";

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

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

generateZshPositionals() treats all variadic args as optional by hard-coding the position prefix to *::, ignoring whether the Commander Argument is required (<arg...>) vs optional ([arg...]). This makes required variadic args (e.g. <entries...>) behave as optional in completion and can confuse _arguments’ arity handling. Consider using *: for required variadic and *:: for optional variadic (and keep the current non-variadic required/optional handling).

Suggested change
const position = arg.variadic ? "*::" : arg.required ? `${index + 1}:` : "::";
const position = arg.variadic
? arg.required
? "*:"
: "*::"
: arg.required
? `${index + 1}:`
: "::";

Copilot uses AI. Check for mistakes.

@nnish16 nnish16 Apr 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in commit f902855: required variadics now emit *: while optional variadics keep *::, so the generated arity matches Commander semantics.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 534af48f5b

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/completion-cli.ts
Comment on lines +189 to +193
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"')
.replace(/'/g, "'\\''")
.replace(/\[/g, "\\[")
.replace(/\]/g, "\\]");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Escape : in zsh positional message text

generateZshPositionals() emits specs in n:message:action form, but the shared escapeZshDescription() helper does not escape literal colons before inserting argument descriptions into the message field. Positional descriptions in this repo already include : (for example the JSON example in mcp set <value>), so zsh parses the generated spec as extra separators instead of one message, which can corrupt or break completion for those commands. _arguments requires literal colons in message/action text to be escaped, so this escaping needs to be added before positional specs are generated.

Useful? React with 👍 / 👎.

@nnish16 nnish16 Apr 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in commit f902855: the shared zsh description escaping now covers literal colons, which fixes positional specs whose descriptions include values like anthropic:default.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S labels Apr 20, 2026
@nnish16

nnish16 commented Apr 20, 2026 •

Copy link
Copy Markdown
Author

Addressed the current automated review feedback in commit f902855.

Changes included:

  • escape literal colons in zsh positional descriptions
  • keep optional positionals position-bound with indexed N:: specs
  • distinguish required vs optional variadics with *: vs *::
  • add regression coverage for all three cases
  • add a brief note explaining why subcommand specs keep narrower inline escaping

Re-ran: pnpm exec vitest run src/cli/completion-cli.test.ts src/cli/completion-cli.write-state.test.ts

@prtags prtags Bot mentioned this pull request Apr 23, 2026
7 tasks done
@prtags

prtags Bot commented Apr 23, 2026

Copy link
Copy Markdown

Related work from PRtags group pretty-bear-eteg

Title: Open PR duplicate: [Bug]: zsh completion for openclaw wiki ingest does not complete file paths

Number Title
#69305 CLI: complete positional args in zsh completion
#69352* fix: complete zsh positional wiki ingest paths
#69509 fix(cli): add positional argument completion for zsh leaf commands

* This PR

@nnish16

nnish16 commented Apr 25, 2026

Copy link
Copy Markdown
Author

Closing this to reduce stale backlog on my side.

I already pushed one follow-up iteration here, but I don’t want to keep an aging PR open if it isn’t the active fix path for #69293. If this issue still needs work later, I’d rather re-open the effort from current main with a fresh branch.

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

Labels

cli CLI command changes size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: zsh completion for openclaw wiki ingest does not complete file paths

2 participants