Skip to content

CLI: escape zsh completion descriptions - #64490

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
EdenKangdw:fix/cli-completion
Jun 23, 2026
Merged

vincentkoc merged 4 commits into
openclaw:mainfrom
EdenKangdw:fix/cli-completion

Conversation

@EdenKangdw

@EdenKangdw EdenKangdw commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor
image

What Problem This Solves

Zsh completion descriptions are emitted inside double-quoted _arguments specs, but $ and backticks were not escaped. Descriptions such as $OPENCLAW_STATE_DIR/completions or examples wrapped in backticks can be interpreted by zsh instead of being displayed literally.

This can break or corrupt CLI tab-completion output and degrades the developer experience.

Why This Change Was Made

This PR keeps the scope limited to zsh option-description escaping. The branch was repaired in place by ProjectClownfish while preserving @EdenKangdw’s original contributor PR and branch history.

The repair keeps the useful $ and backtick escaping, avoids single-quote escaping that does not apply to this double-quoted zsh context, and adds focused regression coverage.

User Impact

Generated zsh completions display CLI option descriptions with $, backticks, and single quotes literally instead of evaluating or corrupting the description text.

Evidence

Change Type

  • Bug fix
  • Refactor required for the fix

Scope

  • UI / DX

Compatibility

  • Backward compatible: Yes

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Apr 10, 2026
@greptile-apps

greptile-apps Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds escapeZshDoubleQuotedDescription to properly escape $, backticks, ", \, [, and ] in zsh _arguments option descriptions, fixing the reported command not found: models error caused by an unescaped $OPENCLAW_STATE_DIR in a description being shell-evaluated.

One escaping rule in the new function is incorrect: ' is replaced with '\\'' (the single-quote idiom), but generateZshArgs embeds descriptions inside double-quoted zsh strings (\"--flag[${desc}]\"), where ' is already literal. Any option description containing a single quote will display as it'\\''s instead of it's in completions.

Confidence Score: 5/5

Safe to merge; the primary fix is correct and the single-quote escaping edge case only affects completion description display.

All remaining findings are P2: the incorrect '\'' escaping only corrupts displayed description text for options whose descriptions contain a literal single quote (rare in practice), and does not break completion functionality or introduce any security or data-integrity risk.

src/cli/completion-cli.ts — escapeZshDoubleQuotedDescription line 209

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cli/completion-cli.ts
Line: 209

Comment:
**Incorrect `'` escape for double-quoted context**

`'\''` is the idiom for embedding a literal single quote inside a *single-quoted* shell string. Inside a *double-quoted* zsh string — which is exactly what `generateZshArgs` emits (e.g. `"--flag[${desc}]"`) — a `'` is already literal and needs no escaping. The `'\''` sequence therefore writes the extra characters `\`, `'`, `'` verbatim into the description.

For an option description like `"don't retry"`, the generated spec becomes `"--flag[don'\''t retry]"`, which zsh displays as `don'\''t retry` instead of `don't retry`. By contrast, `generateZshSubcmdList` correctly uses `'\''` because it wraps its values in *single* quotes.

```suggestion
    .replace(/\$/g, "\\$")
    .replace(/`/g, "\\`")
    .replace(/\[/g, "\\[")
    .replace(/\]/g, "\\]");
```

Drop the `'` replacement; a single quote inside a zsh double-quoted string requires no escaping.

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

Reviews (1): Last reviewed commit: "CLI: escape zsh completion descriptions" | Re-trigger Greptile

Comment thread src/cli/completion-cli.ts Resolved
@ClawKingAI

This comment was marked as spam.

@EdenKangdw

Copy link
Copy Markdown
Contributor Author

Thank you for the feedback.

This PR is limited to updating zsh completion escaping in src/cli/completion-cli.ts. The earlier parse/build issue was caused by my changes and has now been addressed.

The current failing tests appear to be related to schema/help snapshot mismatches under src/config/* (e.g., embeddedHarness descriptions), which seem unrelated to the CLI completion changes introduced in this PR.

Please let me know if you would like me to investigate this further or adjust anything on my side.

@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 22, 2026, 10:00 PM ET / 02:00 UTC.

Summary
The PR adds zsh option-description escaping for dollar signs and backticks in completion generation, plus regression tests for those metacharacters and single quotes.

PR surface: Source +5, Tests +19. Total +24 across 2 files.

Reproducibility: yes. Source inspection shows current main and v2026.6.9 leave dollar signs and backticks unescaped in double-quoted zsh option specs, and the attached terminal screenshots show the before/after completion behavior.

Review metrics: none identified.

Root-cause cluster
Relationship: canonical
Canonical: #64490
Summary: This PR is the canonical open fix for zsh option-description escaping; related zsh completion PRs are narrower, closed, or adjacent behavior changes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] The latest GitHub status rollup for head 5543a13 still includes a failed Real behavior proof check and in-progress CI/security checks, so maintainers should refresh or wait for required checks before merge.

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused zsh option-description escaping fix after required checks and proof automation are green or consciously refreshed, keeping adjacent zsh autoload and positional-completion work separate.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair is needed; the remaining action is maintainer merge judgment plus current check/proof automation handling.

Security
Cleared: Cleared: the diff only changes CLI completion string escaping and colocated tests, with no dependency, workflow, lockfile, permission, network, artifact, or secret-handling changes.

Review details

Best possible solution:

Land this focused zsh option-description escaping fix after required checks and proof automation are green or consciously refreshed, keeping adjacent zsh autoload and positional-completion work separate.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows current main and v2026.6.9 leave dollar signs and backticks unescaped in double-quoted zsh option specs, and the attached terminal screenshots show the before/after completion behavior.

Is this the best way to solve the issue?

Yes. Escaping at generateZshArgs is the narrowest maintainable fix because option descriptions enter the double-quoted zsh _arguments context there; subcommand descriptions and other shells use separate quoting paths.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1252378018f8.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. Sufficient: before/after terminal screenshots directly show the reported zsh completion error disappearing and the completion menu opening for openclaw models.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): Sufficient: before/after terminal screenshots directly show the reported zsh completion error disappearing and the completion menu opening for openclaw models.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a normal-priority CLI completion bugfix with limited blast radius in generated zsh completion output.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): Sufficient: before/after terminal screenshots directly show the reported zsh completion error disappearing and the completion menu opening for openclaw models.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sufficient: before/after terminal screenshots directly show the reported zsh completion error disappearing and the completion menu opening for openclaw models.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Sufficient: before/after terminal screenshots directly show the reported zsh completion error disappearing and the completion menu opening for openclaw models.
Evidence reviewed

PR surface:

Source +5, Tests +19. Total +24 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 6 +5
Tests 1 19 0 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 30 6 +24

What I checked:

Likely related people:

  • shakkernerd: The shell completion generator surface was introduced in the original completion subcommand work. (role: feature introducer; confidence: high; commits: 14c77f82959e; files: src/cli/completion-cli.ts)
  • hydro13: Authored the merged zsh compdef deferral fix and adjacent zsh integration coverage in the same source and test files. (role: recent zsh completion contributor; confidence: high; commits: 6be14ab388eb; files: src/cli/completion-cli.ts, src/cli/completion-cli.test.ts)
  • yiShanXin: Carried completion-generator hardening and generated-shell coverage through the same files and invariants. (role: adjacent completion hardening contributor; confidence: medium; commits: bbb0c3e5d7d9; files: src/cli/completion-cli.ts, src/cli/completion-cli.test.ts)
  • vincentkoc: Recent history and release/current-main provenance show repeated touches around the CLI completion source and tests. (role: recent area contributor; confidence: medium; commits: c0b6183b7bc0, c645ec4555c0; files: src/cli/completion-cli.ts, src/cli/completion-cli.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@EdenKangdw

Copy link
Copy Markdown
Contributor Author

Thanks for catching that. The PR body was stale and still described the earlier $line → $words dispatch issue.

I've updated it to reflect the current diff, which focuses on escaping $ and backticks in double-quoted zsh _arguments option descriptions, with regression coverage for both cases.

@EdenKangdw

EdenKangdw commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor Author
image

It works well on my local zsh smoke test.

I verified that openclaw models <TAB> opens the completion menu correctly and no longer throws _openclaw_models: command not found: models.

I've attached a screenshot of the successful result for reference.

@EdenKangdw

Copy link
Copy Markdown
Contributor Author

The CI is failing with exit code 1 during test cleanup, but all 1,148 tests
pass. This appears to be an infrastructure issue unrelated to my changes.

See: https://github.com/openclaw/openclaw/actions/runs/24263439527/job/70852919846?pr=64490

Could you advise on whether this is a known issue or if there's anything I
can do to help resolve it?

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Jun 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 5, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed stale Marked as stale due to inactivity triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 6, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 6, 2026
@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 14, 2026
@clawsweeper clawsweeper Bot mentioned this pull request Jun 20, 2026
4 of 16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants